Symptoms

Consider the following scenario:

  • You have a SQL CLR function in SQL Server 2016 and 2017.

  • The CLR function invokes Transact-SQL statements through impersonation calls, such as by calling the EXECUTE AS statement.

In this scenario, the execution fails, and you receive the following error message:

Msg 6522, Level 16, State 1, Procedure PrcedureName, Line 0 [Batch Start Line LineNumber]

A .NET Framework error occurred during execution of user-defined routine or aggregate "ProcedureName":

System.Data.SqlClient.SqlException: The server principal "LoginName" is not able to access the database "DatabaseName" under the current security context.

Resolution

This fix is included in Cumulative Update 1 for SQL Server 2017.

Service pack information for SQL Server 2016

This issue is fixed in the following service pack for SQL Server:

       Service Pack 2 for SQL Server 2016

About SQL Server 2017 builds

Each new build for SQL Server 2017 contains all the hotfixes and security fixes that were in the previous build. We recommend that you install the latest build for SQL Server 2017.

Service packs are cumulative. Each new service pack contains all the fixes that are in previous service packs, together with any new fixes. Our recommendation is to apply the latest service pack and the latest cumulative update for that service pack. You do not have to install a previous service pack before you install the latest service pack. Use Table 1 in the following article for finding more information about the latest service pack and latest cumulative update.

How to determine the version, edition and update level of SQL Server and its components

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

Need more help?

Expand your skills
Explore Training
Get new features first
Join Microsoft Insiders

Was this information helpful?

What affected your experience?

Any additional feedback? (Optional)

Thank you for your feedback!

×