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.
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.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.