7

I am currently building a Web Application Project in Visual Studio 2010 and, until recently, have not needed to use the scaffolded code for Memberships, Users and Roles etc that are stored in the ASPNETDB.mdf database file. I have been running the project on the Visual Studio Web Server, IIS Express (from Visual studio) and also IIS7.5 without a problem.

However, I now need to incorporate User accounts and when I use the scaffolded code to log in, I get a server error stating:

An attempt to attach an auto-named database for file C:\Users\User\Documents\COMP6059\PomumV2\PomumV2\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

This error only occurs when I am using either the IIS Express or IIS7.5 web server. The Visual Studio Web Server works fine.

I have followed instructions from http://support.microsoft.com/?kbid=2002980 to no avail.

Below is my connection string for the database:

<add name="ApplicationServices"
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
     providerName="System.Data.SqlClient" />

The error occurs on the following line of the AccountController.cs file (which is auto-generated)

...  if (Membership.ValidateUser(model.UserName, model.Password)) { ...

I did read somewhere that I might need to move the database into SQL Server Management Studio and then attach visual studio via that, but I was unable to log into the database.

I want this to be able to run on IIS7.5. Does anyone have any ideas on how to solve this issue?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Mabbage
  • 775
  • 1
  • 7
  • 12

4 Answers4

4

This is potentially an issue with the account you are running IIS under not having access to that file.

Assign full permissions to that folder for the Network Service account.

You can temporarily try 'everyone' and see if it resolves the issue, and work backwards from there.

Also ensure its not in use by the other web server (process explorer/sysinternals can help show you that)

Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
  • The groups Everyone and NETWORK SERVICE have full control over the App_Data directory but am still getting the same thing. Fairly certain its not being used by any other web server. Got hold of process explorer, but not sure what I'm looking for. – Mabbage Jan 05 '12 at 18:59
  • search for the db name in process explorer and if its in use it will show the process that has it open. it could be open in Visual studio, the VS web server could still be holding on, etc. – Adam Tuliper Jan 05 '12 at 19:46
  • I've given 'full control' to NETWORK SERVICE over my entire Documents folder and that seems to have resolved the above issue. I am now presented with another error about 'failed log in for NT AUTHORITY\NETWORK SERVER', but shall pose as another questions as it seems a separate enough issue. – Mabbage Jan 05 '12 at 19:54
1

check that your folder is not read-only. Works for me

Ron Chong
  • 39
  • 3
0

It appears the OP has resolved the issue but I though it worthwhile tagging on my solution as it may help others in the future.....

I had a similar problem where the localDB went into apparent 'Read-Only' mode on the live server but worked fine on my local dev laptop.

After reading numerous post like this, and trying everything I could find, it still didn't work.

By chance I went into IIS on the live server and noticed that there were 3 database connections identified. 2 were inherited -I dont know where from- and the third was locally declared(eg in the site web.config).

I deleted the 2 inherited connections and, voila! Now it works fine.

Phill Healey
  • 3,084
  • 2
  • 33
  • 67
0

Had this issue after migration from VS2013 to VS2015 Community, while tried to open project's database .mdf file from Visual Studio 2013 folder. Then I copied project with database file to newly created Visual Studio 2015 folder and issue was solved.