Reputation: 11137
I added an external Data Source to my C# app (I've placed it on the root directory in a folder named 'data') but when I run the program I get an error at con.Open()
:
An attempt to attach an auto-named database for file C:\Users\alex\documents\visual studio 2010\Projects\Network_Remote_Monitoring\Network_Remote_Monitoring\bin\Debug\data\bd.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Here is my source code :
con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\data\\bd.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
ds1 = new DataSet();
ds2 = new DataSet();
con.Open();
string sql = "SELECT * From localitati";
da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
da.Fill(ds1, "localitati");
sql = "SELECT * From sucursale";
da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
da.Fill(ds1, "sucursale");
con.Close();
Upvotes: 0
Views: 194
Reputation: 22555
I think you have a same problem as this question: connect to .mdf file in vs2010 , wpf application I answer it there, but it's just my guess. because it is usual problem.
Upvotes: 1
Reputation: 33071
Does the account that is running your application have access to the data folder?
Upvotes: 0