Je tente d'apprendre le framework de synchronisation. J'ai suivi pas à pas la documentation MSDN et cela n'a pas fonctionné. Surpris?! Ce dont j'ai besoin est de synchroniser une base de données SQL Express avec la base de données SQL Express. En lisant sur l'approvisionnement et d'autres préparatifs que je dois faire, je ne pourrais jamais trouver si cela doit être exécuté chaque fois que je veux utiliser la synchronisation. Je veux dire, provision -> sync -> deprovision. Une autre chose est que je reçois cette étrange exception en faisant étape par étape l'échantillon MSDN. DbProvisioningException "MomScope" existe déjà ... ne devrait pas exister?Sync Framework DbProvisioningException
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
}
Tous les échantillons de synchronisation appropriés? Donc, je peux comprendre correctement comment créer cette tâche?
Merci.