How to: Implement a COM-Based Custom Conflict Resolver for a Merge Article (Replication Programming)
The Microsoft.SqlServer.Replication.BusinessLogicSupport namespace implements an interface that enables you to write complex business logic to handle events and resolve conflicts that occur during the merge replication synchronization process. For more information, see How to: Implement a Business Logic Handler for a Merge Article (Replication Programming).You can also write your own native code-based custom business logic to resolve conflicts. This logic is built as a COM component and compiled into dynamic-link libraries (DLL), using products such as Microsoft Visual C++. Such a COM–based custom conflict resolver must implement the ICustomResolver interface, which is designed specifically for conflict resolution.
To create and register a COM-based custom conflict resolver
In a COM-compatible authoring environment, add references to the Custom Conflict Resolver library.
For a Visual C++ project, use the #import directive to import this library into your project.
Create a class that implements the ICustomResolver interface.
Implement certain methods and properties.
Build the project to create the custom conflict resolver library file.
Deploy the library in the directory containing the merge agent executable (usually \Microsoft SQL Server\100\COM).
Note
A custom conflict resolver must be deployed at the Subscriber for a pull subscription, at the Distributor for a push subscription, or at the Web server used with Web synchronization.
Register the custom conflict resolver library using regsvr32.exe from the deployment directory as follows:
regsvr32.exe mycustomresolver.dll
(For a .NET COM interop component, use RegAsm.exe instead.)
At the Publisher, execute sp_enumcustomresolvers (Transact-SQL) to verify that the library is not already registered as a custom conflict resolver.
To register the library as a custom conflict resolver, execute sp_registercustomresolver (Transact-SQL), at the Distributor. Specify the friendly name of the COM object for @article_resolver, the library's ID (CLSID) for @resolver_clsid, and a value of false for @is_dotnet_assembly.
Note
When no longer needed, a custom conflict resolver can be unregistered using sp_unregistercustomresolver (Transact-SQL).
(Optional) On a cluster, repeat steps 5-8 to register the custom resolver on all nodes of the cluster. This is required to ensure that the custom resolver will be able to properly load the reconciler following a failover.
To use a custom conflict resolver with a new table article
At the Publisher, execute sp_enumcustomresolvers (Transact-SQL) and note the friendly name of the desired resolver.
At the Publisher on the publication database, execute sp_addmergearticle (Transact-SQL) to define an article. Specify the friendly name of the article resolver from step 1 for @article_resolver. For more information, see How to: Define an Article (Replication Transact-SQL Programming).
To use a custom conflict resolver with an existing table article
At the Publisher, execute sp_enumcustomresolvers (Transact-SQL) and note the friendly name of the desired resolver.
Execute sp_changemergearticle (Transact-SQL), specifying @publication, @article, a value of article_resolver for @property, and the friendly name of the article resolver from step 1 for @value.