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
string DBPath = "C:\\Users\\...or use a literal like this:string DBPath = @"C:\Users\.... Do not do both.