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,043
    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,375
    Likes Received:
    388
    Trophy Points:
    83

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice