Sql Microsoft Sync Framework-列值的范围和跟踪

Sql Microsoft Sync Framework-列值的范围和跟踪,sql,sql-server,sync,microsoft-sync-framework,Sql,Sql Server,Sync,Microsoft Sync Framework,我的任务是弄清楚这个系统是如何工作的,而在这些问题上,我只是一个新手,所以要友善 我有我的同步和运行的样本数据库进行测试。我使用的是Visual Studio,使用的是C#。下面是我当前同步设置的代码 // define a new scope named ProductsScope DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("ProductsScope"); //

我的任务是弄清楚这个系统是如何工作的,而在这些问题上,我只是一个新手,所以要友善

我有我的同步和运行的样本数据库进行测试。我使用的是Visual Studio,使用的是C#。下面是我当前同步设置的代码

        // define a new scope named ProductsScope
        DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("ProductsScope");

        // get the description of the Products table from SyncDB dtabase
        DbSyncTableDescription tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Products", serverConn);

        // add the table description to the sync scope definition
        scopeDesc.Tables.Add(tableDesc);

        // setting my provision

        // create a server scope provisioning object based on the ProductScope
        SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc);

        // skipping the creation of table since table already exists on server
        serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);

        // start the provisioning process
        serverProvision.Apply();
 // create the sync orhcestrator
        SyncOrchestrator syncOrchestrator = new SyncOrchestrator();

        // set local provider of orchestrator to a CE sync provider associated with the 
        // ProductsScope in the SyncCompactDB compact client database
        syncOrchestrator.LocalProvider = new SqlSyncProvider("ProductsScope", clientConn);

        // set the remote provider of orchestrator to a server sync provider associated with
        // the ProductsScope in the SyncDB server database
        syncOrchestrator.RemoteProvider = new SqlSyncProvider("ProductsScope", serverConn);

        // 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);
        ((SqlSyncProvider)syncOrchestrator.RemoteProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);

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

        //


        // this will show me the statistics after sync
        Console.WriteLine("Start Time: " + syncStats.SyncStartTime);
        Console.WriteLine("Total Changes Uploaded: " + syncStats.UploadChangesTotal);
        Console.WriteLine("Total Changes Downloaded: " + syncStats.DownloadChangesTotal);
        Console.WriteLine("Complete Time: " + syncStats.SyncEndTime);
        Console.WriteLine(String.Empty);}

        static void Program_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)
这是我的同步代码

        // define a new scope named ProductsScope
        DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("ProductsScope");

        // get the description of the Products table from SyncDB dtabase
        DbSyncTableDescription tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Products", serverConn);

        // add the table description to the sync scope definition
        scopeDesc.Tables.Add(tableDesc);

        // setting my provision

        // create a server scope provisioning object based on the ProductScope
        SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc);

        // skipping the creation of table since table already exists on server
        serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);

        // start the provisioning process
        serverProvision.Apply();
 // create the sync orhcestrator
        SyncOrchestrator syncOrchestrator = new SyncOrchestrator();

        // set local provider of orchestrator to a CE sync provider associated with the 
        // ProductsScope in the SyncCompactDB compact client database
        syncOrchestrator.LocalProvider = new SqlSyncProvider("ProductsScope", clientConn);

        // set the remote provider of orchestrator to a server sync provider associated with
        // the ProductsScope in the SyncDB server database
        syncOrchestrator.RemoteProvider = new SqlSyncProvider("ProductsScope", serverConn);

        // 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);
        ((SqlSyncProvider)syncOrchestrator.RemoteProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);

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

        //


        // this will show me the statistics after sync
        Console.WriteLine("Start Time: " + syncStats.SyncStartTime);
        Console.WriteLine("Total Changes Uploaded: " + syncStats.UploadChangesTotal);
        Console.WriteLine("Total Changes Downloaded: " + syncStats.DownloadChangesTotal);
        Console.WriteLine("Complete Time: " + syncStats.SyncEndTime);
        Console.WriteLine(String.Empty);}

        static void Program_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)
销售代表1将第1行中的地址更改为125 Anywhere,销售代表2将第1行中的电话更改为555-5556,是否有办法设置跟踪更改的内容,以便我的最终结果是两位销售代表都具有:

Column   ID (PK)  Name        Phone     Address
Row      1        John Smith  555-5556  125 Anywhere St
Row      2        Jane Smith  555-5555  124 Anywhere St
同步完成后。正如我刚才所说,它需要整行并重写到最后一行。导致多个用户对同一记录所做的更改无法正确处理


我确信这与范围和跟踪的设置有关,但谷歌没有给出任何答案。任何剪贴、链接或建议都很好。

同步框架更改跟踪在行级别。它没有专门记录更改了哪一列,只记录了一行被插入/更新/删除的事实

如果在多个复制副本中更新了一行,则会导致冲突。您应该能够捕获ApplyChangeFailed事件中的冲突,并决定如何解决冲突(例如,服务器赢、客户端赢、在行上执行自定义处理等)