Connecting to MvcMucisStore.mdf gives "access denied"

Aug 23, 2010 at 7:05 PM

I have sql server 2008 Express sp1 64 bit, vs2010 Wxpress, running under Windows 7 Home Premium

 

On page 34 I cannot connect to the MvcMusicStore.mdf as it errors with "Access Denied". However if I create StoreDB.edmx by clicking on Modles folder and adding it there it works and the application runs.

The problem comes when running ASP.net Configuration as when I click on Security it fails because it cannot run the user instance. I am sure it is a permissions thing as I can connect to the database with from vs2010 but not using the .mdf file.

My user login is an administration account and I am the dbo of the databases but cannot work out what is wrong. I have been searching the internet for a solution for days and tried all sorts of things but no joy.

 

Many thanks for your help in advance

Chris

 

Coordinator
Aug 23, 2010 at 7:21 PM

This means that the user account that SQL Server Express is running under doesn't have read/write file permissions for aspnetdb.mdf and aspnetdb_log.mdf. The user account associated with SQL Server Express is not necessarily your user account - often it's NETWORK SERVICE. Take a look at this thread on StackOverflow: http://stackoverflow.com/questions/1134151/user-permission-error-when-accessing-user-instance-database-from-asp-net

Aug 23, 2010 at 8:25 PM

Many thanks for your reply. The ASPNETDB.mdf appears in App_Data and I have checked the users for that database and Mvcmusicstore and they seem to be the same with the same rights. I have checked their properties and made them the same but still cannot connect to mvcmusicstore.mdf.

I have read through the link you sent and the links from that but could not get a solution from it

Any further advice is welcome.

Coordinator
Aug 23, 2010 at 8:31 PM

Can you verify that both the MDF and LDF files are not marked read-only? Also, can you send a stack trace and the full exception message?

Aug 24, 2010 at 8:28 PM

The mdf & ldf files are not read-only. I have discovered a lot of stuff about user instances on the internet which I will go through to see if I can get it working. The main problem is sorting out the permissions because W7 Home Premium does not allow you to manage groups. Mostly what I have read about user instances is how they are going to be dropped in the next version of sql server and they are only available in the express versions anyway. 

If it is not a big ask I would appreciate knowing how I could complete the sample without using user instances. It's a great exercise and I have learnt a lot so far and have almost got it working but failed on sorting out the security because I cannot configure it with the ASP.Net Configuration tool.

Many thanks for your help

Aug 24, 2010 at 9:43 PM

I have got it working now, including running the ASP.net configuration tool.

I removed everything from App_Data and reconnected to the databases using the Database Explorer, the connection strings are:

      <add name="ApplicationServices" connectionString="Data Source=CHRIS-PC\sqlexpress;Initial Catalog=C:\USERS\CHRIS\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\MVCMUSICSTORE\MVCMUSICSTORE\APP_DATA\ASPNETDB.MDF;Integrated Security=True;" providerName="System.Data.SqlClient" />


      <add name="MvcMusicStoreEntities" connectionString="metadata=res://*/Models.StoreDB.csdl|res://*/Models.StoreDB.ssdl|res://*/Models.StoreDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=CHRIS-PC\sqlexpress;Initial Catalog=MvcMusicStore;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

 

I just created the entity model by right-clicking on Models and adding the ADO.Entity Data Model as in the tutorial; rebuilt the application and "hey presto" it started working.

I am now going to try and set up the roles and users; but at least I can now run the tool and click on the Security tab without error.

Many thanks for your prompt answers to my queries

 

Chris

Coordinator
Aug 25, 2010 at 12:57 AM

Sorry for the hassle. Glad you got it working!

Sep 15, 2010 at 9:38 PM
chriscann wrote:

I have got it working now, including running the ASP.net configuration tool.

I removed everything from App_Data and reconnected to the databases using the Database Explorer, the connection strings are:

      <add name="ApplicationServices" connectionString="Data Source=CHRIS-PC\sqlexpress;Initial Catalog=C:\USERS\CHRIS\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\MVCMUSICSTORE\MVCMUSICSTORE\APP_DATA\ASPNETDB.MDF;Integrated Security=True;" providerName="System.Data.SqlClient" />


      <add name="MvcMusicStoreEntities" connectionString="metadata=res://*/Models.StoreDB.csdl|res://*/Models.StoreDB.ssdl|res://*/Models.StoreDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=CHRIS-PC\sqlexpress;Initial Catalog=MvcMusicStore;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

 

I just created the entity model by right-clicking on Models and adding the ADO.Entity Data Model as in the tutorial; rebuilt the application and "hey presto" it started working.

I am now going to try and set up the roles and users; but at least I can now run the tool and click on the Security tab without error.

Many thanks for your prompt answers to my queries

 

Chris

 Where you able to add both database instances with one ADO.Entity Data Model?  How are you doing that?  When I create two, one for each instance, I get all kinds of duplication errors!

Jan 10, 2011 at 8:48 AM
Edited Jan 10, 2011 at 8:54 AM

Hi, 

 

I am having the same problem you had? Could you please give me a hand here? How can I get the connection for "ApplicationServices" and how is it related to the application?

Whenever I try to execute the application it stops here:

 

        private List GetTopSellingAlbums(int count)
        {
            // Group the order details by album and return
            // the albums with the highest count

            return storeDB.Albums
                .OrderByDescending(a => a.OrderDetails.Count())
                .Take(count)
                .ToList();
        }

Thank you in advance. 

Jan 12, 2011 at 11:51 PM

Hi Guys

 

I did not create the ADO Entity model with both databases. The Application Services connection string is for the Membership database as described on page 64 of the PDF. App_Data does not work in the final released version of VS2010.

It is a long time since I completed this exercise so I have enclosed the code for my web.config as it may help you> If these clues do not solve the problem please get back to me and I will investigate further.

 

Good luck

 

 

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration>
  <connectionStrings>

      <add name="ApplicationServices" connectionString="Data Source=CHRIS-PC\;Initial Catalog=C:\USERS\CHRIS\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\MVCMUSICSTORE\MVCMUSICSTORE\APP_DATA\ASPNETDB.MDF;Integrated Security=True;" providerName="System.Data.SqlClient" />
      <add name="MvcMusicStoreEntities" connectionString="metadata=res://*/Models.StoreDB.csdl|res://*/Models.StoreDB.ssdl|res://*/Models.StoreDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=CHRIS-PC\;Initial Catalog=MvcMusicStore;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /></connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>
    <membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
      </providers>
    </profile>
    <roleManager enabled="true">
      <providers>
        <clear />
        <add connectionStringName="ApplicationServices" applicationName="/"
          name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
        <add applicationName="/" name="AspNetWindowsTokenRoleProvider"
          type="System.Web.Security.WindowsTokenRoleProvider" />
      </providers>
    </roleManager>
    <pages>
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="MvcMusicStore" />
        <add namespace="MvcMusicStore.Models" />
        <add namespace="MvcMusicStore.Helpers"/>
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Jan 13, 2011 at 3:32 PM

I managed to use a real database instead of the file provided. Thanks anyway for your help.

Regards.