1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Access SQL Mobile from Desktop Application (.NET)

Discussion in 'ASP.NET' started by naimish, Sep 3, 2009.

  1. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth

    Introduction



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

    Background



    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

    Code:
    //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
    sqlceCon.Open();
    //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
    sqlceCon.Close();

    Thanks :D
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83

Share This Page