FIX: Snapshot Agent fails when you publish UDF’s to SQL Server 2016 Distributor in Transactional Replication

Symptoms

Assume that you have a setup where Microsoft SQL Server 2016 is acting as Distributor and SQL Server 2014 or SQL Server 2012 is acting as Publisher. In this setup, if you create a snapshot, or a transactional or merge publication on SQL Server 2012 or SQL Server 2014 Publisher with user-defined function (UDF) as an article, then Snapshot Agent fails while scripting UDF, and you receive an error message that resembles the following:

Script failed for UserDefinedFunction 'schema.functionname'

The following error message is seen from the Snapshot Agent job history: 

<DateTime> [5%] The replication agent had encountered an exception
<DateTime> Source: Unknown
<DateTime> Exception Type: Microsoft.SqlServer.Management.Smo.FailedOperationException
<DateTime> Exception Message: Script failed for UserDefinedFunction 'schema.functionname'
<DateTime> Message Code: Not Applicable 

Cause

This issue occurs because the Snapshot Agent uses SMO Miscrosft.SqlServer.Smo.dll to script articles. SQL server 2016 adds a new SMO property IsNativelyCompiled for In-Memory functions/stored procedures. This property isn't presented in SQL Server whose version is earlier than SQL Server 2016. When you run the Snapshot Agent on Distributor for SQL Server 2016, it uses Microsoft.SqlServer.Smo.dll of SQL Server 2016, but it tries to check for SMO property IsNativelyCompiled against SQL Server 2012 or 2014 Publisher and it fails with the above error.

Resolution

This issue is fixed in the following cumulative update for SQL Server:

Cumulative Update 4 for SQL Server 2016



About cumulative updates for SQL Server

Workaround

To work around this issue, create user-defined functions (UDF’s) manually on the Subscriber.

Status

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

References

Learn about the terminology that Microsoft uses to describe software updates.
Properties

Article ID: 3197883 - Last Review: 17 ጃንዩ 2017 - Revision: 7

ግብረመልስ