Hi i got an error, for many days i suffering from how to connect with database.
i m using sql server 2008 R2
I have two database one is using Applications services called ASPNET.mdf and other is created Customer.mdf, i hosted my web application on local server at wwwroot directyly ASPNET.mdf can be accessible by my application, but while
connecting to HealthCareDB.mdf i am getting error
Unable to open the physical file "C:\Database\HealthCareDB.MDF". Operating system error 5: "5(Access is denied.)".
An attempt to attach an auto-named database for file C:\Database\HealthCareDB.MDF failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
When i gave Network Access to this database then i got again an error
Unable to open the physical file "C:\Database\HealthCareDB_log.ldf". Operating system error 5: "5(Access is denied.)".
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Database\HealthCareDB_log.ldf'.
Could not open new database 'C:\DATABASE\HEALTHCAREDB.MDF'. CREATE DATABASE is aborted.
An attempt to attach an auto-named database for file C:\Database\HealthCareDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
File activation failure. The physical file name "C:\Database\HealthCareDB_log.ldf" may be incorrect.
could you please help me to came out from this situation.
Reading the error is seems like you are trying to overwrite or create a DB that is already there...
I have not used the property but, you have the AttachDbFilename specified in you connection string and after reviewing BOL, that specifies to attach the mdf to an instance. In your case it sounds like you already have the DBs attached and running
"Fortunately, the SQL Server client code includes an option called AttachDBFilename, which eliminates the need to have a DBA attach the database files to a server before they can be used. When the AttachDBFilename keyword is included in a connection string,
the specified file is attached to the SQL Server instance and the client is connected to the newly attached database. The argument to the AttachDBFilename option is the name of the file to attach. Here is an example."
I recommend using a standard security connection string which can be found here