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:
-
Client A and client B synchronize with the server.
-
A row is updated at client A, and then client A synchronizes. There is no conflict, and the row is applied at the server.
-
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.
-
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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
2010-05-10 如何设置Hyper-V的虚拟机快捷方式