简体   繁体   中英

SQL Server database - cannot connect to it

I am trying to connect my SQL Server database file with a C# application but it is throwing an error. I have already searched for many solutions but none of them are working.

An attempt to attach an auto-named database for file

C:\\Users\\John\\documents\\visual studio 2010\\Projects\\myDb.mdf A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Here is my code for conn:

string DBPath = @"C:\\Users\\SayyedHashmatAli\\Desktop\\IqraLibrarySystem\\IqraLibrarySystem\\IqraLibrarySystemDatabase.mdf";
System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=" + DBPath + ";Integrated Security=True;Connect Timeout=30;User Instance=True");

Please help. Thanks

\\SQLEXPRESS

This is a SQL Server Express installation. The account it runs under must be able to access...

C:\\Users\\SayyedHashmatAli\\Desktop

which is not possible - this is a user private folder. It is among the WORST POSSIBLE PLACES. It is not only in your private folder (and I doubt you forced SQL Server to run under your user account), it is ON YOUR DESKTOP - a place a database has no business being, ever.

Put it into a place that the server actually can read.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM