Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
2.25/5 (4 votes)
See more:
Hello,

I am working with mobile windows application.I designed some pages. I need to store some data in database. Its giving DataSource path is not valid error. Any one can help how to connect database and how to install database in mobile.


System.Data.SqlServerCe.SqlCeConnection con = new System.Data.SqlServerCe.SqlCeConnection("Data Source=.//Mobile.sdf");
            System.Data.SqlServerCe.SqlCeCommand com = new System.Data.SqlServerCe.SqlCeCommand("insert into Emp values('" + textBox1.Text + "')", con);
            con.Open();
            com.ExecuteNonQuery();
            con.Close();


In the above code i am getting this exception:

The database file cannot be found. Check the path to the database. [ Data Source = .//Mobile.sdf ]


[Edited]Code is blocked in "pre" tags[/Edited]
Posted
Updated 4-Apr-11 19:37pm
v7
Comments
Prerak Patel 4-Apr-11 6:16am    
share some code
OriginalGriff 4-Apr-11 6:18am    
What kind of database? Where is it? Which version Windows mobile?
OriginalGriff 4-Apr-11 7:07am    
You have updated your question, but we still need the information we asked for:
What kind of database is it?
Where is the database actually located?
What is the connection string you are using?
Which version of Windows Mobile are we talking about?
Wild-Programmer 4-Apr-11 7:15am    
Your question reminds me of Backstreet Boys album - Incomplete :)

If you develop for WinCE 5.0 - 6.5 you should copy database.sdf file into your mobile. Also you should install Microsoft SQL Server Compact Edition on your mobile.

Connection string:

Data Source=database.sdf;Encrypt Database=True;Password=myPassword;File Mode=shared read;Persist Security Info=False;
 
Share this answer
 
Comments
Mada Naga Sankar 5-Apr-11 0:00am    
can tou tell how to install it in Emulator?
_Ares!!! 5-Apr-11 10:42am    
Sorry, I didn't work with emulator! Although you can share flash card and copy these files. Then you can install it from emulator directly.
If you are coding windows ce 5.0 - 6.5 and developing using VS2005 or VS2008, then you must copy the db to the root directory where the exe is and then use use reflection to get the path of the .sdf file using

C#
string dbPath;
            dbPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            dbPath=dbPath.Substring(0,dbPath.LastIndexOf(@"\")+1);


then you can use

C#
System.Data.SqlServerCe.SqlCeConnection con = new System.Data.SqlServerCe.SqlCeConnection("Data Source=" + dbPath +"\Mobile.sdf");


Hope this helps....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900