Error in Connecting to Database

Posted by Raj.Trivedi under ASP.NET on 5/6/2014 | Points: 10 | Views : 545 | 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..

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved



Responses

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

Up
0
Down
Hi

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

you can refer this thread

http://forums.asp.net/t/879454.aspx?An+attempt+to+attach+an+auto+named+database+for+file+failed

http://stackoverflow.com/questions/12566036/an-attempt-to-attach-an-auto-named-database-for-file-database1-mdf-failed




Thanks and Regards
Chandradev
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

Up
0
Down
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/6dfdcc22-7a81-4e8f-a947-c1ce6982d4b3/flustered-a-database-with-the-same-name-exists-or-specified-file-cannot-be-opened-or-it-is?forum=sqlexpress

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

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

Login to post response