Skip to main content
Bounty Awarded with 50 reputation awarded by ABS
Incorporated comments; improved formatting
Source Link
Paul White
  • 95.7k
  • 30
  • 440
  • 691

To customize the merge process, you'll need to mplementimplement a custom business logic handler (requires .NET code - cannot be implemented using TSQL):. See https://msdn.microsoft.com/en-us/library/ms152495(v=sql.110).aspxExecute Business Logic During Merge Synchronization in the documentation. It is available in SQL Server 2012 and later. 

Override methods Update, Insert and commitCommit to transform changed rows, and conflict resolver method to modify conflict logic. Can't use TSQLT-SQL, must be done with .NET code. The main limitation is that each overridable method is called once for every row (like SSIS row transformations), to the best of my knowledge there isn't a method called on all changed rows.

Applicable to any version 2012 +.

There are some work aroundsworkarounds to handle your case, but this the general solution.

This is the BOL c#C# template.:

using System; using System.Text; using System.Data; using System.Data.Common; using Microsoft.SqlServer.Replication.BusinessLogicSupport; using Microsoft.Samples.SqlServer.BusinessLogicHandler; namespace Microsoft.Samples.SqlServer.BusinessLogicHandler { public class OrderEntryBusinessLogicHandler : Microsoft.SqlServer.Replication.BusinessLogicSupport.BusinessLogicModule { // Variables to hold server names. private string publisherName; private string subscriberName; public OrderEntryBusinessLogicHandler() { } // Implement the Initialize method to get publication // and subscription information. public override void Initialize( string publisher, string subscriber, string distributor, string publisherDB, string subscriberDB, string articleName) { // Set the Publisher and Subscriber names. publisherName = publisher; subscriberName = subscriber; } // Declare what types of row changes, conflicts, or errors to handle. override public ChangeStates HandledChangeStates { get { // Handle Subscriber inserts, updates and deletes. return ChangeStates.SubscriberInserts | ChangeStates.SubscriberUpdates | ChangeStates.SubscriberDeletes; } } public override ActionOnDataChange InsertHandler(SourceIdentifier insertSource, DataSet insertedDataSet, ref DataSet customDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for updates } public override ActionOnDataChange UpdateHandler(SourceIdentifier updateSource, DataSet updatedDataSet, ref DataSet customDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for updates } public override ActionOnDataDelete DeleteHandler(SourceIdentifier deleteSource, DataSet deletedDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for deletes } } 
using System; using System.Text; using System.Data; using System.Data.Common; using Microsoft.SqlServer.Replication.BusinessLogicSupport; using Microsoft.Samples.SqlServer.BusinessLogicHandler; namespace Microsoft.Samples.SqlServer.BusinessLogicHandler { public class OrderEntryBusinessLogicHandler : Microsoft.SqlServer.Replication.BusinessLogicSupport.BusinessLogicModule { // Variables to hold server names. private string publisherName; private string subscriberName; public OrderEntryBusinessLogicHandler() { } // Implement the Initialize method to get publication // and subscription information. public override void Initialize( string publisher, string subscriber, string distributor, string publisherDB, string subscriberDB, string articleName) { // Set the Publisher and Subscriber names. publisherName = publisher; subscriberName = subscriber; } // Declare what types of row changes, conflicts, or errors to handle. override public ChangeStates HandledChangeStates { get { // Handle Subscriber inserts, updates and deletes. return ChangeStates.SubscriberInserts | ChangeStates.SubscriberUpdates | ChangeStates.SubscriberDeletes; } } public override ActionOnDataChange InsertHandler(SourceIdentifier insertSource, DataSet insertedDataSet, ref DataSet customDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for updates } public override ActionOnDataChange UpdateHandler(SourceIdentifier updateSource, DataSet updatedDataSet, ref DataSet customDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for updates } public override ActionOnDataDelete DeleteHandler(SourceIdentifier deleteSource, DataSet deletedDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for deletes } } 

To customize merge process, you'll need to mplement a custom business logic handler (requires .NET code - cannot be implemented using TSQL): https://msdn.microsoft.com/en-us/library/ms152495(v=sql.110).aspx. Override methods Update, Insert and commit to transform changed rows, and conflict resolver method to modify conflict logic. Can't use TSQL, must be done with .NET code. The main limitation is that each overridable method is called once for every row (like SSIS row transformations), to the best of my knowledge there isn't a method called on all changed rows.

Applicable to any version 2012 +.

There are some work arounds to handle your case, but this the general solution.

This is the BOL c# template.

using System; using System.Text; using System.Data; using System.Data.Common; using Microsoft.SqlServer.Replication.BusinessLogicSupport; using Microsoft.Samples.SqlServer.BusinessLogicHandler; namespace Microsoft.Samples.SqlServer.BusinessLogicHandler { public class OrderEntryBusinessLogicHandler : Microsoft.SqlServer.Replication.BusinessLogicSupport.BusinessLogicModule { // Variables to hold server names. private string publisherName; private string subscriberName; public OrderEntryBusinessLogicHandler() { } // Implement the Initialize method to get publication // and subscription information. public override void Initialize( string publisher, string subscriber, string distributor, string publisherDB, string subscriberDB, string articleName) { // Set the Publisher and Subscriber names. publisherName = publisher; subscriberName = subscriber; } // Declare what types of row changes, conflicts, or errors to handle. override public ChangeStates HandledChangeStates { get { // Handle Subscriber inserts, updates and deletes. return ChangeStates.SubscriberInserts | ChangeStates.SubscriberUpdates | ChangeStates.SubscriberDeletes; } } public override ActionOnDataChange InsertHandler(SourceIdentifier insertSource, DataSet insertedDataSet, ref DataSet customDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for updates } public override ActionOnDataChange UpdateHandler(SourceIdentifier updateSource, DataSet updatedDataSet, ref DataSet customDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for updates } public override ActionOnDataDelete DeleteHandler(SourceIdentifier deleteSource, DataSet deletedDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for deletes } } 

To customize the merge process, you'll need to implement a custom business logic handler (requires .NET code - cannot be implemented using TSQL). See Execute Business Logic During Merge Synchronization in the documentation. It is available in SQL Server 2012 and later. 

Override methods Update, Insert and Commit to transform changed rows, and conflict resolver method to modify conflict logic. Can't use T-SQL, must be done with .NET code. The main limitation is that each overridable method is called once for every row (like SSIS row transformations), to the best of my knowledge there isn't a method called on all changed rows.

There are some workarounds to handle your case, but this the general solution.

This is the BOL C# template:

using System; using System.Text; using System.Data; using System.Data.Common; using Microsoft.SqlServer.Replication.BusinessLogicSupport; using Microsoft.Samples.SqlServer.BusinessLogicHandler; namespace Microsoft.Samples.SqlServer.BusinessLogicHandler { public class OrderEntryBusinessLogicHandler : Microsoft.SqlServer.Replication.BusinessLogicSupport.BusinessLogicModule { // Variables to hold server names. private string publisherName; private string subscriberName; public OrderEntryBusinessLogicHandler() { } // Implement the Initialize method to get publication // and subscription information. public override void Initialize( string publisher, string subscriber, string distributor, string publisherDB, string subscriberDB, string articleName) { // Set the Publisher and Subscriber names. publisherName = publisher; subscriberName = subscriber; } // Declare what types of row changes, conflicts, or errors to handle. override public ChangeStates HandledChangeStates { get { // Handle Subscriber inserts, updates and deletes. return ChangeStates.SubscriberInserts | ChangeStates.SubscriberUpdates | ChangeStates.SubscriberDeletes; } } public override ActionOnDataChange InsertHandler(SourceIdentifier insertSource, DataSet insertedDataSet, ref DataSet customDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for updates } public override ActionOnDataChange UpdateHandler(SourceIdentifier updateSource, DataSet updatedDataSet, ref DataSet customDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for updates } public override ActionOnDataDelete DeleteHandler(SourceIdentifier deleteSource, DataSet deletedDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for deletes } } 
added 31 characters in body
Source Link

To customize merge process, you'll need to mplement a custom business logic handler (requires .NET code - cannot be implemented using TSQL): https://msdn.microsoft.com/en-us/library/ms152495(v=sql.110).aspx. Override methods Update, Insert and commit to transform changed rows, and conflict resolver method to modify conflict logic. Can't use TSQL, must be done with .NET code. The main limitation is that each overridable method is called once for every row (like SSIS row transformations), so you're limited to doing things that can be reducedthe best of my knowledge there isn't a method called on all changed rows.

Applicable to row transformationsany version 2012 +.

There are some work arounds to handle your case, but this the general solution.

To customize merge process, you'll need to mplement a custom business logic handler (requires .NET code - cannot be implemented using TSQL): https://msdn.microsoft.com/en-us/library/ms152495(v=sql.110).aspx. Override methods Update, Insert and commit to transform changed rows, and conflict resolver method to modify conflict logic. Can't use TSQL, must be done with .NET code. The main limitation is that each overridable method is called once for every row, so you're limited to doing things that can be reduced to row transformations.

To customize merge process, you'll need to mplement a custom business logic handler (requires .NET code - cannot be implemented using TSQL): https://msdn.microsoft.com/en-us/library/ms152495(v=sql.110).aspx. Override methods Update, Insert and commit to transform changed rows, and conflict resolver method to modify conflict logic. Can't use TSQL, must be done with .NET code. The main limitation is that each overridable method is called once for every row (like SSIS row transformations), to the best of my knowledge there isn't a method called on all changed rows.

Applicable to any version 2012 +.

There are some work arounds to handle your case, but this the general solution.

added 82 characters in body
Source Link

To customize merge process, you'll need to mplement a custom business logic handler (requires .NET code - cannot be implemented using TSQL): https://learn.microsoft.com/en-us/sql/relational- databases/replication/implement-a-business-logic-handler-for-a-merge-articlehttps://msdn.microsoft.com/en-us/library/ms152495(v=sql.110).aspx. Override methods Update, Insert and commit to transform changed rows, and conflict resolver method to modify conflict logic. Can't use TSQL, must be done with .NET code. The main limitation is that each overridable method is called once for every row, so you're limited to doing things that can be reduced to row transformations.

This is the BOL c# template.

using System; using System.Text; using System.Data; using System.Data.Common; using Microsoft.SqlServer.Replication.BusinessLogicSupport; using Microsoft.Samples.SqlServer.BusinessLogicHandler; namespace Microsoft.Samples.SqlServer.BusinessLogicHandler { public class OrderEntryBusinessLogicHandler : Microsoft.SqlServer.Replication.BusinessLogicSupport.BusinessLogicModule { // Variables to hold server names. private string publisherName; private string subscriberName; public OrderEntryBusinessLogicHandler() { } // Implement the Initialize method to get publication // and subscription information. public override void Initialize( string publisher, string subscriber, string distributor, string publisherDB, string subscriberDB, string articleName) { // Set the Publisher and Subscriber names. publisherName = publisher; subscriberName = subscriber; } // Declare what types of row changes, conflicts, or errors to handle. override public ChangeStates HandledChangeStates { get { // Handle Subscriber inserts, updates and deletes. return ChangeStates.SubscriberInserts | ChangeStates.SubscriberUpdates | ChangeStates.SubscriberDeletes; } } public override ActionOnDataChange InsertHandler(SourceIdentifier insertSource, DataSet insertedDataSet, ref DataSet customDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for updates } public override ActionOnDataChange UpdateHandler(SourceIdentifier updateSource, DataSet updatedDataSet, ref DataSet customDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for updates } public override ActionOnDataDelete DeleteHandler(SourceIdentifier deleteSource, DataSet deletedDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for deletes } } 

To customize merge process, you'll need to mplement a custom business logic handler (requires .NET code - cannot be implemented using TSQL): https://learn.microsoft.com/en-us/sql/relational- databases/replication/implement-a-business-logic-handler-for-a-merge-article. Override methods Update, Insert and commit to transform changed rows, and conflict resolver method to modify conflict logic. Can't use TSQL, must be done with .NET code. The main limitation is that each overridable method is called once for every row, so you're limited to doing things that can be reduced to row transformations.

To customize merge process, you'll need to mplement a custom business logic handler (requires .NET code - cannot be implemented using TSQL): https://msdn.microsoft.com/en-us/library/ms152495(v=sql.110).aspx. Override methods Update, Insert and commit to transform changed rows, and conflict resolver method to modify conflict logic. Can't use TSQL, must be done with .NET code. The main limitation is that each overridable method is called once for every row, so you're limited to doing things that can be reduced to row transformations.

This is the BOL c# template.

using System; using System.Text; using System.Data; using System.Data.Common; using Microsoft.SqlServer.Replication.BusinessLogicSupport; using Microsoft.Samples.SqlServer.BusinessLogicHandler; namespace Microsoft.Samples.SqlServer.BusinessLogicHandler { public class OrderEntryBusinessLogicHandler : Microsoft.SqlServer.Replication.BusinessLogicSupport.BusinessLogicModule { // Variables to hold server names. private string publisherName; private string subscriberName; public OrderEntryBusinessLogicHandler() { } // Implement the Initialize method to get publication // and subscription information. public override void Initialize( string publisher, string subscriber, string distributor, string publisherDB, string subscriberDB, string articleName) { // Set the Publisher and Subscriber names. publisherName = publisher; subscriberName = subscriber; } // Declare what types of row changes, conflicts, or errors to handle. override public ChangeStates HandledChangeStates { get { // Handle Subscriber inserts, updates and deletes. return ChangeStates.SubscriberInserts | ChangeStates.SubscriberUpdates | ChangeStates.SubscriberDeletes; } } public override ActionOnDataChange InsertHandler(SourceIdentifier insertSource, DataSet insertedDataSet, ref DataSet customDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for updates } public override ActionOnDataChange UpdateHandler(SourceIdentifier updateSource, DataSet updatedDataSet, ref DataSet customDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for updates } public override ActionOnDataDelete DeleteHandler(SourceIdentifier deleteSource, DataSet deletedDataSet, ref int historyLogLevel, ref string historyLogMessage) { // custom logic for deletes } } 
added 82 characters in body
Source Link
Loading
Source Link
Loading