如何在 Sql Compact DB 中同步合并订阅(在移动设备模拟器上)
我使用 SQL ManagementStudio 2008 创建了 SQL 3.5 Compact DB (TestCompact.sdf),并创建了对现有出版物的订阅。使用 SQL Management Studio 可以正常工作。我已将 TestCompact.sdf 传输到 Windows Mobile 5 模拟器设备,并且使用 QueryAnalyzer for Mobile 我可以查询 TestCompact.sdf 中的现有表。我不知道如何在该移动设备上启动复制同步。我是否需要编写一些 C# 代码,或者可以做得更简单吗?
编辑:(在回复我的问题后添加) 也许 C# 代码为我完成的工作对某人有用: (使用 SQL Management Studio - 我的 Compact DB 的现有订阅的属性)我阅读了 replObj 属性的值是什么)
private void btnSync_Click(object sender, EventArgs e)
{
SqlCeConnection sqlCeConn = null;
SqlCeReplication replObj = new SqlCeReplication();
string connString = @"data source=\My Documents\TestReplicationCompactDB.sdf;Password=bero";
replObj.InternetUrl = @"http://192.168.99.99/VirtualDirectoryForCompactDBReplication/sqlcesa35.dll";;
replObj.PublisherDatabase = "TestReplicationDB";
replObj.PublisherSecurityMode = SecurityType.NTAuthentication;;
replObj.Publisher = @"DBTESTSRV\SQL2008";
replObj.Publication = "TestReplication2";
replObj.Subscriber = "TestReplication";
replObj.SubscriberConnectionString = @"data source=\My Documents\TestReplicationCompactDB.sdf;Password=bero";
replObj.InternetLogin = @"ares\intor";
replObj.InternetPassword = "intor";
try
{
sqlCeConn = new SqlCeConnection(connString);
sqlCeConn.Open();
replObj.Synchronize();
sqlCeConn.Close();
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
if (sqlCeConn != null && sqlCeConn.State == ConnectionState.Open)
sqlCeConn.Close();
return;
}
string countPublisherChanges = replObj.PublisherChanges.ToString();
string countSubScriberChanges = replObj.SubscriberChanges.ToString();
MessageBox.Show(String.Format("Finished with {0} subscriber changes and with {1} publisher changes", countSubScriberChanges, countPublisherChanges));
}
Using SQL ManagementStudio 2008 I created SQL 3.5 Compact DB (TestCompact.sdf) and I have created subscription to existing Publication. Using SQL Management Studio it is working. I have transfered TestCompact.sdf to Windows Mobile 5 emulator device and with QueryAnalyzer for Mobile I could query existing tables in TestCompact.sdf. I don't know how to start replication synchronization on that mobile device. Do I need to write some C# code or it is possible do it more simple?
EDIT: (Added after reply on my question)
Maybe it will be useful for someone what C# code did the job for me:
(Using SQL Management Studio - Properties on existing subscription for my Compact DB) I read what are values for a replObj properties)
private void btnSync_Click(object sender, EventArgs e)
{
SqlCeConnection sqlCeConn = null;
SqlCeReplication replObj = new SqlCeReplication();
string connString = @"data source=\My Documents\TestReplicationCompactDB.sdf;Password=bero";
replObj.InternetUrl = @"http://192.168.99.99/VirtualDirectoryForCompactDBReplication/sqlcesa35.dll";;
replObj.PublisherDatabase = "TestReplicationDB";
replObj.PublisherSecurityMode = SecurityType.NTAuthentication;;
replObj.Publisher = @"DBTESTSRV\SQL2008";
replObj.Publication = "TestReplication2";
replObj.Subscriber = "TestReplication";
replObj.SubscriberConnectionString = @"data source=\My Documents\TestReplicationCompactDB.sdf;Password=bero";
replObj.InternetLogin = @"ares\intor";
replObj.InternetPassword = "intor";
try
{
sqlCeConn = new SqlCeConnection(connString);
sqlCeConn.Open();
replObj.Synchronize();
sqlCeConn.Close();
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
if (sqlCeConn != null && sqlCeConn.State == ConnectionState.Open)
sqlCeConn.Close();
return;
}
string countPublisherChanges = replObj.PublisherChanges.ToString();
string countSubScriberChanges = replObj.SubscriberChanges.ToString();
MessageBox.Show(String.Format("Finished with {0} subscriber changes and with {1} publisher changes", countSubScriberChanges, countPublisherChanges));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要编写“一些”C# 代码,在 SSMS 中的向导结束时您会获得一些示例代码。
You need to write "some" C# code, at the end of the Wizard in SSMS you get some sample code.