Hi All,
I am new to C# programming.I have developed an application in C# that involves data retrieval from database, for which i used custom connection string as default one was not saving data permanently in database.
I am using MS Visual C#2010 Express.
so my code for connection was:
string conString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\PC\\Documents\\Visual Studio 2010\\Projects\\My_app\\My_app\\Myapp_records.mdf;Integrated Security=True;User Instance=True";
SqlConnection con = new SqlConnection(conString);
con.Open();
and so on.....
Now when i want to publish this application and run on some other pc, it cannot find path to my database and gives error.
Error:
An attempt to attach an auto-named database for file ****** myapp_records.mdf failed.
can Please some one recommend me solution so that, i can install my application on other PC's with database attached. or path to database can be mentioned in settings some where.
Thanks
Bilal Farooq
Loading
Amit ChoudharyPosted Jan 14, 2011, 2:24 AM
If you are publishing your application to some other comuter then please make sure to reuse your connection string:
1. SQLEXPRESS is installed on other machine with the same windows authentication mode.
2. The database file should be copied while publishing at the same location where it was on your previous pc i.e., "C:\\Users\\PC\\Documents\\Visual Studio 2010\\Projects\\My_app\\My_app\\Myapp_records.mdf"
Hope this helps you.
Thanks
Vijay YadavPosted Jan 19, 2011, 2:18 AM
Yeah rite..
Thanks
Vijay
Bilal MalikPosted Jan 19, 2011, 2:15 AM
yeah, this much i understand but i don't get it that y that pc has lower version as it was installed at the time of installing my_app by it self. So it should have installed the same upgraded version of the database. rite ?
Thanks
Bilal Farooq
Vijay YadavPosted Jan 19, 2011, 2:13 AM
Got your query, actly its a issue of version. The database which you have on that PC is of lower version(say SQL sever 2005) and you have made your database in higher version(say SQL sever 2008) hence you are getting this problem...
Thanks
Vijay
Bilal MalikPosted Jan 19, 2011, 2:06 AM
Thanks for ur replies, this error got removed but now error i am getting is of database. It says that sql server installed on PC is of version 665 and database my_app is using is of version 661, some thing like that, what can be done with this ?
Thanks
Bilal Farooq
Vijay YadavPosted Jan 19, 2011, 12:59 AM
You can use this code if you don't to save the oth the same location
string strCon = "Data Source=.;AttachDBFilename=|DataDirectory|Myapp_records.mdf;integrated security=true;";
Just you have to do is to save your .mdf file in debug folder (for ex: bin/debug/Myapp_records.mdf)
Thanks
Vijay
Bilal MalikPosted Jan 16, 2011, 9:37 AM
Bilal MalikPosted Jan 16, 2011, 8:20 AM
Thanks for your reply, can u plz explain this a bit more for me " then please make sure to reuse your connection string: ".
Thanks
Bilal Farooq
Madhu KPosted Jan 13, 2011, 11:51 PM
http://social.msdn.microsoft.com/forums/en-US/sqldatabaseengine/thread/fafe818f-8aa3-46cd-bb69-55e540e7a62e/