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.
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