views:

303

answers:

4

Hello,

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

A: 

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
The are same user account at the web folder and on the app_data folder
Frozzare
The IIS user obvoiusly has read access then, but does it have write access?
Pete
Yes it have that to
Frozzare
A: 

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

Mahin
The database exist in the folder
Frozzare
i am just curious whether you have any file named MyDatabase.mdf in "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data" folder ?
Mahin
Not in that folder, in the app_data folder for my web project
Frozzare
Do you have given permission APP_Data folder for NETWORK_SERVICE user ?
Mahin
Yes it already have that
Frozzare
Can you check the link below http://msdn.microsoft.com/en-us/library/ms998320.aspxCheck sections named File Access and SQL Server and confirm if your IIS and Local SQL Server has enough permissions.
Mahin
A: 

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

Best Regards!!!

MRFerocius
Well, if it allready have that? And it not working with that?
Frozzare
Try this, gives you some steps to solve the issue;http://www.aspspider.com/resources/Resource170.aspxAlso give permission to NETWORK SERVICE on that folder.-
MRFerocius