Error in Connecting to Database

Posted by Raj.Trivedi under ASP.NET on 5/6/2014 | Points: 10 | Views : 1309 | Status : [Member] [MVP] | Replies : 2
Hello Friends,

I had an .mdf file in the app_data folder and now i have attached the database to the my SQL server 2008 r2 express server.

The database got attached successfully.

Then i deleted the app_data folder from the website and changed the connection string as.

cn = new SqlConnection("Data Source=.;Initial Catalog=RNW;User id=sa;Password=sqluser");

When i am trying to connect to the database i am getting the following error

Error :-
"An attempt to attach an auto-named database for file F:\Real Estate Web\App_Data\RealEstate.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share"

I checked everything and even created a new website and added all the files manually without the app_data folder but it is still giving the same error.

Any suggestions..

"Sharing is Caring"
Please mark as answer if your Query is resolved


Posted by: Chandradev819 on: 5/7/2014 [Member] Starter | Points: 25


It looks like connection string problem. Try to get connection string from sqldatasource control. It will give exact path.

you can refer this thread

Thanks and Regards
My Blog

Raj.Trivedi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 5/7/2014 [Member] [MVP] Platinum | Points: 25


Mark This Response as Answer

Raj.Trivedi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response