How to: Handle Data Conflicts and Errors 【转载】

MSF(Microsoft Sync Framework)是微软的一套数据同步框架,其中一个典型场景就是实现本地数据库与远程数据库之间的数据同步,这样可以比较容易实现脱机应用程序的架构

有关MSF的一些具体内容,可以参考微软的官方网站

http://msdn.microsoft.com/en-us/library/bb902854.aspx

这一篇特别摘录一下有关数据同步时的冲突检测和处理,完整的文档参考下面

http://msdn.microsoft.com/en-us/library/bb725997.aspx

Understanding Data Conflicts and Errors

In Sync Framework, conflicts and errors are detected at the level of the row. A row is in conflict if it has been changed at more than one node between synchronizations. Errors during synchronization typically involve a constraint violation, such as a duplicate primary key. Applications should be designed to avoid conflicts if they can, because conflict detection and resolution introduce additional complexity, processing, and network traffic. The most common ways to avoid conflicts are as follows: to update a table at only one node (typically the server); or to filter data so that only one node updates a particular row. For more information about filtering, see How to: Filter Rows and Columns. In some applications, conflicts cannot be avoided. For example, in a sales force application, two salespeople might share a territory. Both salespeople could update the data for the same customer and orders. Therefore, Sync Framework provides a set of features that can be used to detect and resolve conflicts.

Data conflicts can occur in any synchronization scenario in which changes are made at more than one node. Obviously, conflicts can occur in bidirectional synchronization, but they can also occur in download-only and upload-only synchronization. For example, if a row is deleted at the server and the same row is updated at the client, there is a conflict when Sync Framework tries to apply the update that is uploaded to the server. Conflicts are always between the server and the client that is currently synchronizing. Consider the following example:

  1. Client A and client B synchronize with the server.

  2. A row is updated at client A, and then client A synchronizes. There is no conflict, and the row is applied at the server.

  3. The same row is updated at client B, and then client B synchronizes. The row from client B is now in conflict with the row from the server because of the update that originated at client A.

  4. If you resolve this conflict in favor of the server, Sync Framework can apply the row from the server to client B. If you resolve in favor of client B, Sync Framework can apply the row from client B to the server. During a later synchronization between client A and the server, the update that originated at client B is applied to client A.

原文地址:https://www.cnblogs.com/chenxizhang/p/2042652.html