同步框架 DbProvisioningException

发布于 2024-10-03 05:42:38 字数 2763 浏览 0 评论 0 原文

我正在尝试学习同步框架。 我按照MSDN文档一步步操作,但没有成功。惊讶吗?! 我需要的是将 SQL Express 数据库与 SQL Express 数据库同步。 在阅读有关配置和我需要做的其他准备的内容时,我永远无法找到是否每次我想使用同步时都必须运行它。我的意思是,规定->同步->取消配置。 另一件事是,我在逐步制作 MSDN 示例时遇到了这个奇怪的异常。

DbProvisioningException“MomScope”已经存在...不应该存在吗?

代码:

private void InitializeSync()
{
    SqlConnection sourceConn = new SqlConnection(ConfigManager.Config.SourceSyncConnectionString);
    SqlConnection myConn = new SqlConnection(ConfigManager.Config.ConnectionString);

    #region SET SOURCE PROVIDER

    SqlSyncProvider sourceSqlProv = new SqlSyncProvider("MomSync", sourceConn);

    DbSyncScopeDescription sourceScope = new DbSyncScopeDescription("MomScope");

    DbSyncTableDescription productsSourceTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Mom_Products", sourceConn);
    DbSyncTableDescription customersSourceTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Mom_Customer", sourceConn);
    DbSyncTableDescription ordersSourceTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Mom_Orders", sourceConn);
    DbSyncTableDescription paymentsSourceTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Mom_Payments", sourceConn);

    sourceScope.Tables.Add(productsSourceTableDesc);
    sourceScope.Tables.Add(customersSourceTableDesc);
    sourceScope.Tables.Add(ordersSourceTableDesc);
    sourceScope.Tables.Add(paymentsSourceTableDesc);

    SqlSyncScopeProvisioning sourceProvision = new SqlSyncScopeProvisioning(sourceConn, sourceScope);
    sourceProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);

    try
    {
        sourceProvision.Apply();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

    #endregion

    #region SET MY PROVIDER

    SqlSyncProvider myProvider = new SqlSyncProvider("MomSync", myConn);

    DbSyncScopeDescription scopeSourceDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope("MomScope", sourceConn); <===== DbProvisioningException (MomScope already exists????)
    SqlSyncScopeProvisioning myProvision = new SqlSyncScopeProvisioning(myConn, scopeSourceDesc);

    try
    {
        myProvision.Apply();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

    #endregion

    #region SET SYNC ORCHESTRATOR

    OrcheStrator = new SyncOrchestrator
                       {
                           LocalProvider = myProvider,
                           RemoteProvider = sourceSqlProv,
                           Direction = SyncDirectionOrder.UploadAndDownload
                       };

    ((SqlSyncProvider)OrcheStrator.LocalProvider).ApplyChangeFailed += ApplyChangeFailedHandler;

    #endregion
}

有合适的同步示例吗?那么我可以正确地弄清楚如何创建这个任务吗?

谢谢。

Im trying to learn Sync framework.
I have followed step by step MSDN Documentation and it didn't work. Surprised?!
What i need is to sync a SQL Express Database with SQL Express Database.
While reading about provisioning and other prepare i need to do, i could never find if this must be run every time i want to use sync. I mean, provision -> sync -> deprovision.
Another thing is that is that i get this strange exception while making step by step the MSDN sample.

DbProvisioningException "MomScope" already exists...shoudn't be exist?

Code:

private void InitializeSync()
{
    SqlConnection sourceConn = new SqlConnection(ConfigManager.Config.SourceSyncConnectionString);
    SqlConnection myConn = new SqlConnection(ConfigManager.Config.ConnectionString);

    #region SET SOURCE PROVIDER

    SqlSyncProvider sourceSqlProv = new SqlSyncProvider("MomSync", sourceConn);

    DbSyncScopeDescription sourceScope = new DbSyncScopeDescription("MomScope");

    DbSyncTableDescription productsSourceTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Mom_Products", sourceConn);
    DbSyncTableDescription customersSourceTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Mom_Customer", sourceConn);
    DbSyncTableDescription ordersSourceTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Mom_Orders", sourceConn);
    DbSyncTableDescription paymentsSourceTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Mom_Payments", sourceConn);

    sourceScope.Tables.Add(productsSourceTableDesc);
    sourceScope.Tables.Add(customersSourceTableDesc);
    sourceScope.Tables.Add(ordersSourceTableDesc);
    sourceScope.Tables.Add(paymentsSourceTableDesc);

    SqlSyncScopeProvisioning sourceProvision = new SqlSyncScopeProvisioning(sourceConn, sourceScope);
    sourceProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);

    try
    {
        sourceProvision.Apply();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

    #endregion

    #region SET MY PROVIDER

    SqlSyncProvider myProvider = new SqlSyncProvider("MomSync", myConn);

    DbSyncScopeDescription scopeSourceDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope("MomScope", sourceConn); <===== DbProvisioningException (MomScope already exists????)
    SqlSyncScopeProvisioning myProvision = new SqlSyncScopeProvisioning(myConn, scopeSourceDesc);

    try
    {
        myProvision.Apply();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

    #endregion

    #region SET SYNC ORCHESTRATOR

    OrcheStrator = new SyncOrchestrator
                       {
                           LocalProvider = myProvider,
                           RemoteProvider = sourceSqlProv,
                           Direction = SyncDirectionOrder.UploadAndDownload
                       };

    ((SqlSyncProvider)OrcheStrator.LocalProvider).ApplyChangeFailed += ApplyChangeFailedHandler;

    #endregion
}

Any proper sync samples? So i can figure properly how to create this task?

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

魂归处 2024-10-10 05:42:39

如果有人仍然感兴趣...

只需在 apply() 之前对 sourceProvision.Exists() 进行检查
http://msdn.microsoft.com/en-us/library/dd919024.aspx

Should anyone still be interested...

Just implement a check on sourceProvision.Exists() right before you apply()
http://msdn.microsoft.com/en-us/library/dd919024.aspx

ζ澈沫 2024-10-10 05:42:39

您无需每次在同步前进行配置。可以一次性提供,然后您可以从那里开始同步。当然,如果取消配置发生在某个时间..sycn 之后就无法完成。

就您而言,正如消息所暗示的那样,似乎已经存在同名的内容。通过运行以下语句进行检查

select * from scope_info

如果它返回具有您尝试添加的范围名称的行,您可以执行以下操作。

  1. 取消配置该范围的数据库。但您需要确保该范围没有被其他人使用。

(或)

  1. 使用不同的名称配置数据库

You need not provision everytime before sync. Provision can be one time and then you can sync from there on. Ofcourse if de-provision happens at time ..sycn canot be done after that.

In your case, as the message suggests, there seems to be existing already with that same name. Check by running following statement

select * from scope_info

If it returns rows with scope name which you are trying to add, you can do following things.

  1. De-provision the DBs for that Scope. But you need to make sure that scope is not in use by anyone else.

(OR)

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