1

I get this error message when i try to using sql express:

An attempt to attach an auto-named database for file C:\Users\Name\Documents\Visual Studio 2008\Projects\MyProject\MyWeb\App_Data\MyDatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

My connection string

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True;User Instance=True;

I can't finde out what the problem is. The database exist, it work when i trying to debbug. but not when i run IIS7 at localhost

Joel Coehoorn
  • 380,066
  • 110
  • 546
  • 781

4 Answers4

0

My guess is that IIS7 is running under a different user account that doesn't have both read and write access to the directory and mdf file.

Pete
  • 12,182
  • 8
  • 51
  • 65
0

Do you have any database named MyDatabase or database who has create MyDatabase.mdf as data file in your sql express ?

MRG
  • 3,209
  • 1
  • 25
  • 35
  • The database exist in the folder –  Sep 02 '09 at 11:56
  • i am just curious whether you have any file named MyDatabase.mdf in "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data" folder ? – MRG Sep 02 '09 at 11:58
  • Not in that folder, in the app_data folder for my web project –  Sep 02 '09 at 12:00
  • Do you have given permission APP_Data folder for NETWORK_SERVICE user ? – MRG Sep 02 '09 at 12:01
  • Can you check the link below http://msdn.microsoft.com/en-us/library/ms998320.aspx Check sections named File Access and SQL Server and confirm if your IIS and Local SQL Server has enough permissions. – MRG Sep 02 '09 at 12:12
0

Add read/write premissions for IUSR to the folder where the database is;

Best Regards!!!

MRFerocius
  • 5,439
  • 7
  • 37
  • 46
  • Well, if it allready have that? And it not working with that? –  Sep 02 '09 at 12:09
  • Try this, gives you some steps to solve the issue; http://www.aspspider.com/resources/Resource170.aspx Also give permission to NETWORK SERVICE on that folder.- – MRFerocius Sep 03 '09 at 12:07