Alex Watts
Alex Watts

Reputation: 567

Tracking changes in Microsoft Sync Framework

Below is my code which executes the synchronization between two 2008 SQL Servers. The program successfully synchronizes data between the two servers without issue. The problem however is that, in the logs I generate during this, I notice a very high amount of transactions going from Server2 to Server1 - always in this direction, and always very similar amounts. In order to help track down why this is happening, I would like to create another log file which records the actual row data that is being copied from one server to another every time the script synchronizes the two servers. Is there a way to do this using Sync Framework, or would it be better to make use of another utility within SQL Server to do this? I'm not terribly proficient with databases, so the most basic and straight forward solution would be the most ideal for me.

//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);
}

Upvotes: 0

Views: 617

Answers (1)

JuneT
JuneT

Reputation: 7860

if you create a handler for ChangesSelected or ChangesApplied, there'll be a dataset there that contains the actual data that was selected or applied.

Upvotes: 1

Related Questions