RDA方式同步ce数据库

RDA方式同步ce数据库
首次做移动的程序----数据同步,感觉到.net 是如此的方便!!!!
    首先,得配置好开发环境    装上.net2003   sqlserver2000 以及ce development tols  server tools后,新增一个iis目录并且配置它为ce server agent端
在浏览器中测试http://localhost/sqlce/sscesa20.dll   (sqlce为虚拟目录名称)  返回server agent几字,表明配置正确。
    下面为程序代码:
注意:为确保ce中表为可tracked的   故应先pull   后执行push  submit等操作。
1。pull
   string InternetServer = "http://192.168.10.231/sqlce/sscesa20.dll";
   string InternetUser ="Administrator";
   string InternetPassword = "dszj1207";
   string RemoteConnection = "Provider=sqloledb;Data Source=DSZJ;Initial Catalog=ce;User Id=sa;Password=winwdr";
   string LocalDatabase = "\\My Documents\\rc.sdf";
   string LocalConnection = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=\\My Documents\\rc.sdf";
   string LocalTableName = "students";
   string RemoteTableName = "students";

   SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess(InternetServer, InternetUser, InternetPassword, LocalConnection);
   rda.Pull(LocalTableName,"select * from students", RemoteConnection, RdaTrackOption.TrackingOnWithIndexes, "rdaErrors");
   rda.Dispose();
  }

2。push
SqlCeRemoteDataAccess rda = null;
  
  try
  {
    rda = new SqlCeRemoteDataAccess();
    rda.InternetLogin="Administrator";
    rda.InternetPassword="dszj1207";
    rda.InternetUrl            = "http://192.168.10.231/sqlce/sscesa20.dll";
    rda.LocalConnectionString  = "Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0;Data Source=\\My Documents\\rc.sdf";
    rda.Push("students", rdaOleDbConnectString, RdaBatchOption.BatchingOff);
   }
  catch(SqlCeException ex)
  {
  MessageBox.Show(ex.ToString(), "Error");
}
  finally
 {
    rda.Dispose();
  }
3.。submit
SqlCeRemoteDataAccess rda = null;
   try
   {
    rda = new SqlCeRemoteDataAccess(InternetServer, InternetUser, InternetPassword, LocalConnection);
    rda.SubmitSql("insert into students values('sunjiguang','010547896321','天津')",RemoteConnection);
   }
   catch(SqlCeException ex)
   {
    MessageBox.Show(ex.ToString(), "Error");
   }
   finally
   {
    rda.Dispose();
   }

posted on 2006-07-24 15:29  欧阳  阅读(490)  评论(0编辑  收藏  举报