Go4Expert (http://www.go4expert.com/)
-   ASP.NET (http://www.go4expert.com/articles/asp-net-tutorials/)
-   -   Access SQL Mobile from Desktop Application (.NET) (http://www.go4expert.com/articles/access-sql-mobile-desktop-application-t19280/)

naimish 3Sep2009 11:30

Access SQL Mobile from Desktop Application (.NET)


Accessing the Mobile DB (SQL CE/ SQL Mobile) from desktop application. Synchronization of Desktop/Server DB and SQL Mobile


Following code snippets show how to access SQL CE of a PPC 2003 or Windows Mobile DB from Desktop Application when device is craddled and connected through Microsoft Active Sync.

The code uses the Microsoft.SqlServerCe.Client.dll instead of System.Data.SqlServerCe.dll

The code

Code: C#.NET


//import namesspace
using Microsoft.SqlServerCe.Client;
//Connection string
string conStr = "Data Source = Mobile Device\My Documents\MySQLCeDB.sdf;";
//Create Connection
SqlCeConnection sqlceCon = new SqlCeConnection(conStr);
//open connection
//Create CommandObject
SqlCeCommand sqlceCmd = new SqlCeCommand();
sqlceCmd.CommandType = CommandType.Text;
sqlceCmd.CommandText = "Select count(*) from myTable"; //say Mytable is the source table
sqlceCmd .Connection = sqlceCon;
//Execute Query
int rowCount = sqlceCmd.ExecuteNonQuery();
//Close Connection

Thanks :D

shabbir 3Oct2009 17:07

Re: Access SQL Mobile from Desktop Application (.NET)
Nomination for Article of the month - Sep 2009 Started. Nominate this article.

All times are GMT +5.5. The time now is 17:29.