I have developed and website as for my assignment purpose and then my teacher asked me that he doesn't have SQL Server to run separately my database file so I must have to make built in database. I then added the .mdf file to the App_data folder and used this connection string:

<add name="dbCanberraConnectionString1"
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|latestcanberra.mdf;"
     providerName="System.Data.SqlClient" />

in web.config. But when I tried to run my website it shows an error

Unable to open the physical file "D:\Complete Assignment\Alkandi Final Work\App_Data\latestcanberra.mdf". Operating system error 5: "5(Access is denied.)

An attempt to attach an auto-named database for file D:\Complete Assignment\Alkandi Final Work\App_Data\latestcanberra.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

I am totally stuck with this error from last 3 hours even I tried different methods by searching solutions from different blogs etc

Any idea how to solve this out within less time ?

2

There are 2 answers

0
sabotero On

Give full control to your "Authenticated Users". If there is no this user in the security settings then add it.

In case you are wondering how to do this --- I am on Windows 7 and the steps go like this:

Right-click on the MDF file and click properties. Select the "Security" tab and select your "Authenticated Users" or click 'Edit' Button then 'Add' button then write 'Autheticated Users' and then 'Check Names' button. Then 'OK' button. Click "Edit" and select the "Allow" check-box for "Full Control". OK all the way out.

0
Nikhil Bharambe On

Add a connection string like in the code below. Add only User Instance=True:

<appSettings>
    <add key="dbconn" value="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB_Garment.mdf;User ID=sa;Password=123;Integrated Security=True;Connect Timeout=30;User Instance=True"/>
</appSettings>