.NET SyncFramework同步范围

时间:2017-05-29 15:34:30

标签: .net microsoft-sync-framework

我必须同步两个本地和远程数据库。 如果我有这个例子:

本地数据库: 的 1。约翰 乔 3.标记

远程: 的 1。约翰 2.乔

并且我同步两个数据库,最终结果将是我将在两个数据库中拥有所有三个记录,但同步过程将触发记录#1和#2的错误(无法插入它们),因为它们存在于都。默认情况下,Sync框架在这种情况下不会执行任何操作,只会继续,这对我来说没问题。

有没有办法设置同步范围,以便只同步来自两个数据库的不同记录(因此这些错误不会首先生成)?

我的代码看起来像这样(来自Microsoft的示例代码):

SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(remoteServerConn);
DbSyncScopeDescription remoteScopeDesc = new DbSyncScopeDescription(remoteProvisioningScopeName);
DbSyncTableDescription tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable(remoteTableName, remoteServerConn);
remoteScopeDesc.Tables.Add(tableDesc); 
serverProvision.PopulateFromScopeDescription(remoteScopeDesc);                   serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);    
serverProvision.Apply(); 
SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(localServerConn);
DbSyncScopeDescription localScopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(remoteProvisioningScopeName, remoteServerConn);
clientProvision.PopulateFromScopeDescription(localScopeDesc);
clientProvision.Apply();
SyncOrchestrator syncOrchestrator = new SyncOrchestrator();
syncOrchestrator.LocalProvider = new SqlSyncProvider(remoteProvisioningScopeName, localServerConn);
syncOrchestrator.RemoteProvider = new SqlSyncProvider(remoteProvisioningScopeName, remoteServerConn);    
syncOrchestrator.Direction = syncDirection;
((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);
SyncOperationStatistics syncStats = syncOrchestrator.Synchronize();

1 个答案:

答案 0 :(得分:0)

Sync Framework执行增量同步,即自上次同步以来发生的变化,而不是源和目标之间的差异