【问题标题】:Tracking changes in Microsoft Sync Framework跟踪 Microsoft Sync Framework 中的更改
【发布时间】:2016-09-06 20:58:21
【问题描述】:

以下是我在两个 2008 SQL Server 之间执行同步的代码。该程序成功地在两台服务器之间同步数据,没有问题。然而问题是,在我在此期间生成的日志中,我注意到从 Server2 到 Server1 的大量事务 - 总是在这个方向上,并且总是非常相似的数量。为了帮助追踪发生这种情况的原因,我想创建另一个日志文件,该文件记录每次脚本同步两台服务器时从一台服务器复制到另一台服务器的实际行数据。有没有办法使用 Sync Framework 来做到这一点,或者使用 SQL Server 中的另一个实用程序来做到这一点会更好吗?我对数据库不是很精通,所以最基本和最直接的解决方案对我来说是最理想的。

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

【问题讨论】:

    标签: c# sql .net microsoft-sync-framework


    【解决方案1】:

    如果您为 ChangesSelected 或 ChangesApplied 创建一个处理程序,那里将有一个数据集,其中包含被选择或应用的实际数据。

    【讨论】:

    • 您是说我可以为此创建一个自定义事件处理程序并使用它从 Sync Framework 访问一些对象信息,还是说这在使用 Sync Framework 时已经是一个可用的项目,我只需要添加到代码?
    猜你喜欢
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    • 2014-02-11
    • 2011-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多