A custom SQL Server business logic handler replaces an empty string with an end-of-string character

Article ID: 2598605 - View products that this article applies to.
Expand all | Collapse all

SYMPTOMS

Consider the following scenario:
  • You configure merge replication in Microsoft SQL Server 2012, in Microsoft SQL Server 2008 R2, or in Microsoft SQL Server 2008.
  • The publication contains a table article.
  • The table article contains a column of data type varchar.
  • The varchar column contains an empty string ("").

    Note This issue does not occur with a NULL value or single space value (" ").
  • You configure the table article to use a custom business logic handler.
  • The custom business logic handler handles events that occur during merge replication synchronization.
  • The custom business logic handler uses a custom dataset to return the row.
In this scenario, although no error is returned, the custom business logic handler replaces the empty string with a single end-of-string character. For example, the custom business logic handler replaces the empty string with one of the following strings: 
  • "ASC0"
  • "0x00"  
  • "\0" 
No other data is affected.

CAUSE

This issue occurs because of how the merge agent components and the business logic handler pass data in and out of the intermediate variables.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

WORKAROUND

You may be able to work around this issue by using the nvarchar data type instead of the varchar data type.

MORE INFORMATION

The problem that is described in the "Symptoms" section can occur if the custom business logic handler handles conflicting UPDATE statements at the publisher and subscriber. The empty string is replaced by the single end-of-string character after the publisher or subscriber dataset is copied into the custom dataset, and the custom dataset is then passed to the merge replication reconciler.  

Additionally, this issue occurs if the data is not changed in custom code that resembles the following:       
public override ActionOnUpdateConflict UpdateConflictsHandler(..., ref customDataSet, ...)
        {
            customDataSet = publisherDataSet.Copy();
            conflictLogType = ConflictLogType.ConflictLogPublisher;
            return ActionOnUpdateConflict.AcceptCustomConflictData;
        }

Properties

Article ID: 2598605 - Last Review: May 22, 2012 - Revision: 2.0
APPLIES TO
  • Microsoft SQL Server 2008 Standard
  • Microsoft SQL Server 2008 Enterprise
  • Microsoft SQL Server 2008 R2 Standard
  • Microsoft SQL Server 2008 R2 Enterprise
  • Microsoft SQL Server 2008 R2 Datacenter
  • Microsoft SQL Server 2012 Standard
  • Microsoft SQL Server 2012 Enterprise
  • Microsoft SQL Server 2012 Developer
Keywords: 
kbsurveynew kbprb kbtshoot kbnofix KB2598605

Give Feedback