When conflicts occur during the merge process, a conflict resolver must determine how the conflict is resolved. The resolver applies a set of decision rules to the data in conflict and takes the appropriate action. The conflict resolver also stores information about the conflict by creating a conflict table named conflict_usertablename. The conflict table is stored at the Publisher for applications that use centralized conflict logging, and at the Subscriber for applications that use decentralized conflict logging. The conflict table has the same structure as the original table, and the conflict resolver copies the “losing” version of the row into the conflict table. The “winning” version of the row resides in the actual user table. Columns in the sysmergearticles system table hold information about which tables have related conflict tables, and the names of those tables. Delete conflicts are tracked in the MSmerge_delete_conflicts table.
With some conflicts, you cannot propagate changes from one site to another. For example, if a table must satisfy a UNIQUE constraint and two sites attempt to insert a row with the same key value, there is a conflict. If each insert succeeds, there is no knowledge that the constraint has been violated until an attempt is made to synchronize the sites. This error information is also stored in the conflict table.
Some synchronization problems can be transient, such as locking problems. Other problems, such as the UNIQUE constraint violation, require some user action to restore the convergence. In this case, the appropriate user action might be to delete one of the two conflicting rows. Most referential integrity violations, such as inserting a row with a foreign key while another site is deleting the row with the corresponding primary key, can be either transient or persistent. Microsoft® SQL Server™ attempts automatically to delete the second unique key row to reach the hub.
SQL Server recognizes the necessity for applications to have a flexible scheme for resolving any conflicts that occur during the merge process. When building your application, you have three alternatives for a conflict resolution mechanism:
SQL Server allows you to build a custom conflict resolver using the ICustomResolver interface. However, implementing a custom resolver as a COM object is more complex than implementing a resolver as a custom stored procedure. You are encouraged to use the custom stored procedure conflict resolver whenever possible.
Using a Custom Resolver | sp_addmergearticle |
Merge Replication |