Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
583 views
in Technique[技术] by (71.8m points)

asp.net - Attempt to attach an auto-named database for .mdf file failed

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:UsersUserDocumentsCOMP6059PomumV2PomumV2App_Dataaspnetdb.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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...