sql server compact 3.5 连接 sql server 2005 使用同步复制、RDA(二)

6.同步复制

  本地发布数据库DSHG中的article表,展开sql server 2005 中复制》本地发布,右击本地发布,选择新建发布,发布数据库中,选择要发布的数据库DSHG,发布类型选择合并发布,(合并发布:
在订阅服务器收到已发布数据的初始快照后,发布服务器和订阅服务器可以独立更新已发布数据。更改会定期合并。Microsoft SQL Server Compact Edition 只能订阅合并发布。),在发布对象中选择要发布的article表,一路按提示设置下去,最后发布名是DSHG。

vs2008 代码如下。

 SqlCeReplication repl = null;

            try
            {             
                repl = new SqlCeReplication();
                repl.InternetUrl = "http://192.168.1.118/sqlce35/sqlcesa35.dll";
                repl.InternetLogin = "Administrator";
                repl.InternetPassword = "094182";
                repl.Publisher = "服务器机器名";
                repl.PublisherDatabase = "DSHG";
                repl.PublisherLogin = "sa";
                repl.PublisherPassword = "123465";
                repl.DistributorLogin = "sa";
                repl.DistributorPassword = "123465";
                repl.DistributorAddress = "192.168.1.118";
                repl.Publication = "DSHG";
                repl.Subscriber = "test";
                repl.SubscriberConnectionString = "Data Source=//Micro_sd//test.sdf";                
               
               repl.Synchronize();
              

               string str;
               str = " SubscriberChanges :" + Convert.ToString(repl.SubscriberChanges) + "/n SubscriberConflicts :"+Convert.ToString(repl.SubscriberConflicts);

               str = str + "/n PublisherChanges :" + Convert.ToString(repl.PublisherChanges) + "/n PublisherConflicts :" + Convert.ToString(repl.PublisherConflicts);
               MessageBox.Show(str,"同步信息");

}

以上代码,测试成功。

               

你可能感兴趣的:(C#,sql,server,microsoft,服务器,数据库,string,null)