2017-05-29 71 views
0

我必須同步兩個本地和遠程數據庫。 如果我有這樣的例子:.NET SyncFramework同步範圍

本地數據庫: 1.約翰 2.喬 3.標記

遠程: 1.約翰 2.喬

和我同步兩個數據庫的最終結果將是我將在兩個數據庫中都有三條記錄,但同步過程將觸發記錄#1和#2(不能插入它們)的錯誤,因爲它們都存在於兩個數據庫中。默認情況下,Sync框架在這種情況下不會執行任何操作,只會繼續執行,這對我來說可以。

是否有一種方法可以設置同步範圍,以便只有兩個數據庫中的非相同記錄才能同步(並且因此不會首先生成這些錯誤)?

我的代碼如下所示(從微軟的示例代碼):

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(); 

回答

0

同步框架做增量同步,即自上次同步發生了什麼變化,沒有什麼是源和目標

之間的不同