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 updates for SQL Server:Cumulative Update 2 for SQL Server 2016 SP1Cumulative Update 4 for SQL Server 2016

Each new cumulative update for SQL Server contains all the hotfixes and all the security fixes that were included with the previous cumulative update. Check out the latest cumulative updates for SQL Server:Latest cumulative update for SQL Server 2016

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 terminologythat Microsoft uses to describe software updates.

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.