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

  1. In a COM-compatible authoring environment, add references to the Custom Conflict Resolver library.

  2. For a Visual C++ project, use the #import directive to import this library into your project.

  3. Create a class that implements the ICustomResolver interface.

  4. Implement certain methods and properties.

  5. Build the project to create the custom conflict resolver library file.

  6. Deploy the library in the directory containing the merge agent executable (usually \Microsoft SQL Server\90\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.

  7. Register the custom conflict resolver library using regsvr32.exe from the deployment directory as follows:

    regsvr32.exe mycustomresolver.dll
    
  8. At the Publisher, execute sp_enumcustomresolvers (Transact-SQL) to verify that the library is not already registered as a custom conflict resolver.

  9. 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).

  10. (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

  1. At the Publisher, execute sp_enumcustomresolvers (Transact-SQL) and note the friendly name of the desired resolver.

  2. 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

  1. At the Publisher, execute sp_enumcustomresolvers (Transact-SQL) and note the friendly name of the desired resolver.

  2. 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.

See Also

Other Resources

COM-Based Custom Resolvers

Help and Information

Getting SQL Server 2005 Assistance