SQLCE Connection Problems
-
Hello! I am facing some problems on the development of my mobile simlpe application connecting to an SQLCE database. After searching a bunch of sites, tutorials and Q&A's my code seems to be correct and I can't figure out what's going wrong. This is my code:
SqlCeConnection conn = new SqlCeConnection("Data Source=ChokweDB.sdf"); SqlCeCommand insertForm1 = new SqlCeCommand("INSERT INTO Form1Table (p1,p2,p3,p4,entrevistador,data) values ('" + p1.Text + "','" + p2.Text + "','" + p3Value + "','" + p4Value + "','" + txtEntrevistador.Text + "','" + txtData.Text + "')", conn); conn.Open(); insertForm1.ExecuteNonQuery(); conn.Close();
My database is placed in the home directory of the application (filename ChokweDB.sdf). When I run the code, MVS2008 will simply not find the database:
The database file cannot be found. Check the path to the database. [ Data Source = ChokweDB.sdf ]
Why oh why? What am I missing?
-
Hello! I am facing some problems on the development of my mobile simlpe application connecting to an SQLCE database. After searching a bunch of sites, tutorials and Q&A's my code seems to be correct and I can't figure out what's going wrong. This is my code:
SqlCeConnection conn = new SqlCeConnection("Data Source=ChokweDB.sdf"); SqlCeCommand insertForm1 = new SqlCeCommand("INSERT INTO Form1Table (p1,p2,p3,p4,entrevistador,data) values ('" + p1.Text + "','" + p2.Text + "','" + p3Value + "','" + p4Value + "','" + txtEntrevistador.Text + "','" + txtData.Text + "')", conn); conn.Open(); insertForm1.ExecuteNonQuery(); conn.Close();
My database is placed in the home directory of the application (filename ChokweDB.sdf). When I run the code, MVS2008 will simply not find the database:
The database file cannot be found. Check the path to the database. [ Data Source = ChokweDB.sdf ]
Why oh why? What am I missing?
Hi Vafo, in your code you have to specify exact database path.
string DBPath = @"Program Files\ChokweDB.sdf"; SqlCeConnection conn = new SqlCeConnection("Data Source=" + DBPath );
hope this will help you...Pavan Pareta
modified on Friday, April 24, 2009 2:47 PM
-
Hi Vafo, in your code you have to specify exact database path.
string DBPath = @"Program Files\ChokweDB.sdf"; SqlCeConnection conn = new SqlCeConnection("Data Source=" + DBPath );
hope this will help you...Pavan Pareta
modified on Friday, April 24, 2009 2:47 PM
Can't build, unrecogized escape sequence error after each dash...seen this before..
string dbconn = "@C:\\Documents and Settings\\Vasco\\Ambiente de trabalho\\Serviços de Informática\\ChokweMobile\\ChokweDB.sdf"; SqlCeConnection conn = new SqlCeConnection("Data Source=" + dbconn);
And after some correcting... <pre> string dbconn = @"C:\Documents and Settings\Vasco\Ambiente de trabalho\Serviços de Informática\ChokweMobile\ChokweDB.sdf"; SqlCeConnection conn = new SqlCeConnection("Data Source=" + dbconn); Returns Path not valid. And...
string dbconn = @".\ChokweDB.sdf";
The database file cannot be found. Check the path to the database. [ Data Source = .\ChokweDB.sdf ] The database IS o the same folder as the application - and it really IS there and the name is spelled correctly..
modified on Thursday, April 23, 2009 7:10 AM
-
Hello! I am facing some problems on the development of my mobile simlpe application connecting to an SQLCE database. After searching a bunch of sites, tutorials and Q&A's my code seems to be correct and I can't figure out what's going wrong. This is my code:
SqlCeConnection conn = new SqlCeConnection("Data Source=ChokweDB.sdf"); SqlCeCommand insertForm1 = new SqlCeCommand("INSERT INTO Form1Table (p1,p2,p3,p4,entrevistador,data) values ('" + p1.Text + "','" + p2.Text + "','" + p3Value + "','" + p4Value + "','" + txtEntrevistador.Text + "','" + txtData.Text + "')", conn); conn.Open(); insertForm1.ExecuteNonQuery(); conn.Close();
My database is placed in the home directory of the application (filename ChokweDB.sdf). When I run the code, MVS2008 will simply not find the database:
The database file cannot be found. Check the path to the database. [ Data Source = ChokweDB.sdf ]
Why oh why? What am I missing?
Hi, Add data source in your project. then select your database (.sdf) file in your solution. then click properties then set the value of Copy to Output Directory = Copy Always. Try this. Thanks
~Khatri Mitesh khatrimitesh@hotmail.com Bikaner (Rajasthan) INDIA http://www.youtube.com/watch?v=-oJaaPCrk3Q
-
Hello! I am facing some problems on the development of my mobile simlpe application connecting to an SQLCE database. After searching a bunch of sites, tutorials and Q&A's my code seems to be correct and I can't figure out what's going wrong. This is my code:
SqlCeConnection conn = new SqlCeConnection("Data Source=ChokweDB.sdf"); SqlCeCommand insertForm1 = new SqlCeCommand("INSERT INTO Form1Table (p1,p2,p3,p4,entrevistador,data) values ('" + p1.Text + "','" + p2.Text + "','" + p3Value + "','" + p4Value + "','" + txtEntrevistador.Text + "','" + txtData.Text + "')", conn); conn.Open(); insertForm1.ExecuteNonQuery(); conn.Close();
My database is placed in the home directory of the application (filename ChokweDB.sdf). When I run the code, MVS2008 will simply not find the database:
The database file cannot be found. Check the path to the database. [ Data Source = ChokweDB.sdf ]
Why oh why? What am I missing?
you should to add the data base trough add elements there you can see your data base and can execute program to compile if you want to compile trough mobile device add the data base in mobile device Thanks
-
you should to add the data base trough add elements there you can see your data base and can execute program to compile if you want to compile trough mobile device add the data base in mobile device Thanks
Try this string path = "Data Source ="; path += System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); path += "\\Database.sdf"; then myConnection = new SqlCeConnection(@path); cheers