开发者

Sync Framework DbProvisioningException

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

    SqlSyncPr开发者_Go百科ovider 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.


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜