如何在 Sql Compact DB 中同步合并订阅(在移动设备模拟器上)

发布于 2024-09-06 01:42:38 字数 2009 浏览 5 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩动你心 2024-09-13 01:42:38

您需要编写“一些”C# 代码,在 SSMS 中的向导结束时您会获得一些示例代码。

You need to write "some" C# code, at the end of the Wizard in SSMS you get some sample code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文