我的任务是弄清楚这个系统是如何工作的,当涉及到这些问题时,我几乎不是新手,所以请善待。
我使用示例数据库启动并运行同步以进行测试。我正在使用 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)
{
此时同步是对一行数据的完全重写。我正在寻找的是有关设置同步以识别对单个列所做的更改的小说明(不确定我是否正确地说)。
例如:
Column ID (PK) Name Phone Address
Row 1 John Smith 555-5555 123 Anywhere St
Row 2 Jane Smith 555-5555 124 Anywhere St
销售代表一将第 1 行中的地址更改为 125 Anywhere,销售代表二将第 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
同步完成后。正如我所说,目前它需要整行并重写到最后一个。导致多个用户对同一记录进行的更改没有得到正确处理。
我确信这与范围和跟踪的设置方式有关,但谷歌没有给出任何答案。任何剪辑、链接或建议都会很棒。