Click here to Skip to main content
15,885,985 members
Articles / Mobile Apps

Using SQL Server CE Mobile with SQL Server through RDA

Rate me:
Please Sign up or sign in to vote.
3.41/5 (12 votes)
16 Nov 2006CPOL1 min read 62.1K   563   38   8
This article is on communicating with a server through Remote Data Access objects.

Sample Image - DBManager.jpg

Introduction

In this article, I will talk about Visual Studio .NET mobile developement and the use of RDA Remote Data Access) objects to access data and communicate with a PC. I will show how to synchronize your device with the server and share data. I will focus on RDA and replication. I developed the program for my HP Ipaq HW6500 series Pocket PC. So the screen size may not fit. But you can change it to fit your mobile device's screen size. 

Using the code

Just run the code. It will be installed to your device. The code needs SQL Server CE installed, and sscesa20.dll should be configured. The code uses SQL Server 2000 (2005 has the same manner though) with SP3 and Visual Studio 2003. You can find the required information from here.

An example of the souce code is given below. This is used to pull a table.

C#
SqlCeConnection cn = null;
string rdaOleDbConnectString = 
    "Provider=sqloledb; Data Source=localhost;" + 
    "Initial Catalog=" + DbManager.glbConn.DbName + "; " +
    "User Id=" + DbManager.glbConn.DbUserId + 
    ";Password=" + DbManager.glbConn.DbPassword ;
SqlCeRemoteDataAccess rda = null;
try 
{
    rda = new SqlCeRemoteDataAccess();
    rda.InternetLogin          = DbManager.glbConn.WebUserId;
    rda.InternetPassword       = DbManager.glbConn.WebPassword;
    rda.InternetUrl            = http://+DbManager.glbConn.ServerIp+
                                 "/"+DbManager.glbConn.WebDir+
                                 "/sscesa20.dll";
    rda.LocalConnectionString ="Data Source=\\Program Files\\"+
                               this.txtLocalDb.Text + ".sdf";
    if (this.chkDropTable.Checked)
    { 
        cn = new SqlCeConnection(rda.LocalConnectionString);
        cn.Open();
        SqlCeCommand cmd = cn.CreateCommand();
        cmd.CommandText = "DROP TABLE " + this.txtLocalTable.Text;
        cmd.ExecuteNonQuery();
        if (cn.State != ConnectionState.Closed)
            cn.Close();
    }
    if (this.cmbTrackOption.Text=="TrackingOff")
        rda.Pull(this.txtLocalTable.Text, 
          this.txtQuery.Text, 
          rdaOleDbConnectString,
          RdaTrackOption.TrackingOff,
          "ErrorTable");
    if (this.cmbTrackOption.Text=="TrackingOn")
        rda.Pull(this.txtLocalTable.Text, 
          this.txtQuery.Text, 
          rdaOleDbConnectString,
          RdaTrackOption.TrackingOn,
          "ErrorTable");
    if (this.cmbTrackOption.Text=="TrackingOffWithIndexes")
        rda.Pull(this.txtLocalTable.Text, 
          this.txtQuery.Text, 
          rdaOleDbConnectString,
          RdaTrackOption.TrackingOffWithIndexes,
          "ErrorTable"); ...

Key Points

Unless you enter the names and types of the server parameters correctly, you won't be able to use the DA objects, so please be careful about it.

Please notice that rather than using a DataSet for the DataGrid, one must use DataReaders to make efficient use of memmory.

Also, you have to ensure that sscesa20.dll is configured and working correctly. Make sure the path is right.

Lastly...

As I develop more, I will come up with other Mobile examples.

License

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


Written By
CEO Gravi Information Technologies and Consultancy Ltd
Turkey Turkey
Currently, also an MSc. student in Technical University of Munich, I develop practical application in computer vision for more than 5 years. I design real-time solutions to industrial and practical vision problems, both 3D and 2D. Very interested in developing algorithms in C relating math and vision.

Please visit Gravi's web page (http://www.gravi.com.tr) and my page (http://www.tbirdal.me) to learn more about what we develop.

I admire performance in algorithms.

"Great minds never die, they just tend to infinity..."

Comments and Discussions

 
Generala bug! Pin
885313138-Oct-08 0:47
885313138-Oct-08 0:47 
Generalmissing method exception Pin
mokhabarat3-May-07 12:20
mokhabarat3-May-07 12:20 
GeneralRe: missing method exception Pin
Tolga Birdal3-May-07 23:47
Tolga Birdal3-May-07 23:47 
Generalcontact Pin
theboescho14-Dec-06 7:52
theboescho14-Dec-06 7:52 
QuestionComms over GPRS Pin
djgann19-Nov-06 20:27
djgann19-Nov-06 20:27 
AnswerRe: Comms over GPRS Pin
Tolga Birdal21-Nov-06 13:48
Tolga Birdal21-Nov-06 13:48 
GeneralRe: Comms over GPRS Pin
Tolga Birdal21-Nov-06 13:48
Tolga Birdal21-Nov-06 13:48 
GeneralRe: Comms over GPRS Pin
Tolga Birdal22-Nov-06 11:32
Tolga Birdal22-Nov-06 11:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.