gebeurtenis
31 mrt, 23 - 2 apr, 23
De grootste SQL-, Fabric- en Power BI-leerevenement. 31 maart – 2 april. Gebruik code FABINSIDER om $ 400 te besparen.
Zorg dat u zich vandaag nog registreertDeze browser wordt niet meer ondersteund.
Upgrade naar Microsoft Edge om te profiteren van de nieuwste functies, beveiligingsupdates en technische ondersteuning.
Applies to:
SQL Server
This topic describes how to implement a custom conflict resolver for a Merge article in SQL Server by using Transact-SQL or a COM-based custom resolver.
In this topic
Implement a custom conflict resolver for a Merge article, using:
You can write your own custom conflict resolver as a Transact-SQL stored procedure at each Publisher. During synchronization, this stored procedure is invoked when conflicts are encountered in an article that the resolver was registered to. Information about the conflict row is passed by the Merge Agent to the required parameters of the procedure. Stored procedure-based custom conflict resolvers are always created at the Publisher.
Notitie
Microsoft SQL Server stored procedure resolvers are invoked only to handle row change-based conflicts. They can't be used to handle other types of conflicts like insert failures triggered by PRIMARY KEY violations or unique index constraint violations.
At the Publisher in either the publication or msdb database, create a new system stored procedure that implements the following required parameters:
Parameter | Data type | Description |
---|---|---|
@tableowner | sysname | Name of the owner of the table for which a conflict is being resolved. This is the owner for the table in the publication database. |
@tablename | sysname | Name of the table for which a conflict is being resolved. |
@rowguid | uniqueidentifier | Unique identifier for the row that has the conflict. |
@subscriber | sysname | Name of the server from which a conflicting change is being propagated. |
@subscriber_db | sysname | Name of the database from which a conflicting change is being propagated. |
@log_conflict OUTPUT | int | Sets whether the merge process should log a conflict for later resolution: 0 = Do not log the conflict. 1 = Subscriber is the conflict loser. 2 = Publisher is the conflict loser. |
@conflict_message OUTPUT | nvarchar(512) | Message to be given about the resolution if the conflict is logged. |
@destowner | sysname | The owner of the published table at the Subscriber. |
This stored procedure uses the values passed by the Merge Agent to these parameters to implement your custom conflict resolution logic. It must return a single row result set that's identical in structure to the base table and that contains the data values for the winning version of the row.
Grant EXECUTE permissions on the stored procedure to any logins used by Subscribers to connect to the Publisher.
Execute sp_addmergearticle to define an article.
Specify a value of MicrosoftSQL Server Stored Procedure Resolver for the @article_resolver parameter.
Specify the name of the stored procedure that implements the conflict resolver logic for the @resolver_info parameter.
For more information, see Define an article.
Execute sp_changemergearticle, specifying @publication, @article, a value of article_resolver for @property, and a value of MicrosoftSQL Server Stored ProcedureResolver for @value.
Execute sp_changemergearticle, specifying @publication, @article, a value of resolver_info for @property, and the name of the stored procedure that implements the conflict resolver logic for @value.
The Microsoft.SqlServer.Replication.BusinessLogicSupport namespace implements an interface that enables you to write complex business logic to handle events and to resolve conflicts that occur during the Merge replication synchronization process. For more information, see Implement a Business Logic Handler for a Merge article. 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 (DLLs), using products such as Microsoft Visual C++. This kind of COM-based custom conflict resolver must implement the ICustomResolver interface, which is designed specifically for conflict resolution.
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 that contains the Merge Agent executable (usually \Microsoft SQL Server\100\COM).
Notitie
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 by running regsvr32.exe from the deployment directory as follows:
regsvr32.exe mycustomresolver.dll
At the Publisher, execute sp_enumcustomresolvers (Transact-SQL) to verify that the library isn't 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.
Notitie
When it's no longer needed, you can unregister a custom conflict resolver by using sp_unregistercustomresolver (Transact-SQL).
(Optional) On a cluster, repeat steps 6-9 to register the custom resolver on all nodes of the cluster. These steps are required to make sure that the custom resolver can properly load the reconciler following a failover.
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 Define an 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.
gebeurtenis
31 mrt, 23 - 2 apr, 23
De grootste SQL-, Fabric- en Power BI-leerevenement. 31 maart – 2 april. Gebruik code FABINSIDER om $ 400 te besparen.
Zorg dat u zich vandaag nog registreertTraining
Module
Conflicterende commits vereffenen door samenvoegingsconflicten op te lossen op GitHub - Training
Leer hoe u overlappende commits tussen vertakkingen vereffent met behulp van het oplossen van samenvoegingsconflicten.
Documentatie
Detect & resolve conflicts in logical records (Merge) - SQL Server
Learn about the various combinations of conflict detection and conflict resolution approaches possible when using logical records with Merge replication.
Microsoft COM-Based Resolvers - SQL Server
Advanced Merge Replication Conflict - COM-Based Resolvers
MSmerge_conflicts_info (Transact-SQL) - SQL Server
MSmerge_conflicts_info (Transact-SQL)