2016-09-06 13 views
0

以下は、2つの2008 SQL Server間の同期を実行する私のコードです。プログラムは問題なく2つのサーバー間でデータを正常に同期します。ただし、この間に生成されるログでは、Server2からServer1へのトランザクションの量が非常に多いことに気づいています。常にこの方向にあり、常に非常に似ています。なぜこれが起きているのかを追跡するために、スクリプトが2つのサーバーを同期させるたびに、あるサーバーから別のサーバーにコピーされている実際の行データを記録する別のログファイルを作成したいと思います。 Sync Frameworkを使用してこれを行う方法はありますか、それを行うにはSQL Server内の別のユーティリティを使用する方がよいでしょうか?私はデータベースに熟練しているわけではないので、最も基本的で単純な解決策が私にとって最も理想的です。Microsoft Sync Frameworkでの変更の追跡

//Connection string to the client (what the data flows INTO) 
SqlConnection clientConnection = new SqlConnection("Data Source=OMITTED;Initial Catalog=OMITTED;Integrated Security=SSPI"); 

//Connection string to the database (what the data flows FROM) 
SqlConnection serverConnection = new SqlConnection("Data Source=OMITTED;Initial Catalog=OMITTED;Integrated Security=SSPI"); 

//Create a sync orchestrator 
SyncOrchestrator syncOrchestrator = new SyncOrchestrator(); 

//Set local provider of orchestrator to a sync provider (S2) 
syncOrchestrator.LocalProvider = new SqlSyncProvider("OMITTED", clientConnection); 

//Set remote provider of orchestrator to a server sync provider (S1) 
syncOrchestrator.RemoteProvider = new SqlSyncProvider("OMITTED", serverConnection); 

//Set the direction of sync session to UPload and Download 
syncOrchestrator.Direction = SyncDirectionOrder.UploadAndDownload; 

//Subscribe for errors that occur when applying changes to the client 
((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed); 

//Execute the synchronization process 
SyncOperationStatistics syncStats = syncOrchestrator.Synchronize(); 

//Access specific information about the given file 
FileInfo myFile = new FileInfo(LogFilePath); 

//If the log file does not yet have any data (it's blank), include some header information 
//Otherwise, just append the file with new data 
if (!(myFile.Length > 0)) 
{ 
    string header = "Run Time,Changes Uploaded,Changes Downloaded"; 
    string data = syncStats.SyncStartTime + "," + syncStats.UploadChangesTotal + "," + syncStats.DownloadChangesTotal; 

    LogFileText.Add(header); 
    LogFileText.Add(data); 
} 
else 
{ 
    string data = syncStats.SyncStartTime + "," + syncStats.UploadChangesTotal + "," + syncStats.DownloadChangesTotal; 
    LogFileText.Add(data); 
} 

答えて

1

あなたがChangesSelectedやChangesAppliedのハンドラを作成する場合、選択されたか、適用された実際のデータが含まれていますが、データセットがあります。

+0

あなたは、このためのカスタムイベントハンドラを作成し、Sync Frameworkからオブジェクト情報にアクセスすることができますか、これはコードに追加するだけのSync Frameworkを使用しているときに既に利用可能なアイテムですか? –

+0

を入手できます。あなたはちょうどイベントハンドラを書く必要があります... – JuneT

関連する問題