SQL Server

Troubleshooting SQL Server 2014 CLR Problems

Troubleshooting SQL Server 2014 CLR Problems

If you have problems with SQL Server 2014 Common Language Runtime (CLR) objects, review this
troubleshooting checklist to find potential solutions.

1. Install the latest SQL Server 2014 service pack.

Because many SQL Server 2014 CLR bugs were fixed in SQL Server service packs, you should
install the latest SQL Server service pack.
At the time this article was written the latest SQL Server 2014 service pack was service
pack 1. You can download the SQL Server 2014 service pack 1 at here:
https://www.microsoft.com/en-us/download/details.aspx?id=46694

2. You may receive error 701 when you use a CLR table-valued function (TVF) together with
the CROSS APPLY operator in a query.

The error 701 indicates that there is insufficient system memory to run the query. To work around
this problem, try to rewrite the query to avoid using the CROSS APPLY operator. To resolve this
problem, install the latest SQL Server service pack.

3. Executing the CREATE ASSEMBLY statement to register a CLR assembly in SQL Server 2014
may cause error 6509.

This problem occurs when the access permission of the CREATE ASSEMBLY statement is set to SAFE,
one or more methods in the assembly are very large and have lots of branch instructions. To work
around this problem, you can set the access permission of the CREATE ASSEMBLY statement to UNSAFE.

4. You can find out that .NET Framework execution was aborted by escalation policy
because of out of memory.

This problem may be caused by user code that does not release CLR memory or garbage collection
handles. To resolve this problem, you should rewrite the application code to release CLR memory
or garbage collection handles.

5. The error 6511 or 6513 may occur when using SQL CLR stored procedures, user defined
functions, user defined data types, or user defined aggregates.

The most probable cause of these errors is SQL Server 2014 CLR encountering memory pressure.
To work around this problem, you should avoid caching large amount of data using objects such
as DataTables, avoid using static variables in your code to store large objects and create
objects as late, and release them as early, as possible.

6. You can find out that the CLR module information is represented incorrectly
when you profile managed code that is running in SQL Server 2014 by using
performance tools in Visual Studio Team Edition for Software Developers.

To work around this problem, you can create a separate project that is not a SQL Server project
by using Visual Studio, then profile the separate project and integrate the separate project
into a SQL Server project.

7. The error 6522 may occur when you deploy a CLR trigger that access data from
a remote SQL Server using Windows authentication after impersonating the user
account using WindowsImpersonationContext.

To work around this problem, if you require the functionality of impersonating the caller’s
identity inside a SQL CLR trigger, you should manage the transactions explicitly in your code.
For example, you can use the TransactionScopeOption.Supress method to suppress inbuilt SQL
transaction handling and manage the remote transaction with commit or rollback as per your
requirements.

8. The error 6512 may occur when you use SQL Server 2014 CLR stored procedures,
user defined functions, user defined data types, or user defined aggregates.

This is the error message text: “Failed to initialize the Common Language Runtime (CLR)”.
To resolve this problem, you can reinstall .NET Framework.

9. Fatal exception occurs when you run a query that contains CLR functions against
an indexed view in SQL Server 2014.

This is SQL Server 2014 bug. This bug was first fixed in Cumulative Update package 4
for SQL Server 2014. You can download the Cumulative Update package 4 for
SQL Server 2014 at here:
https://support.microsoft.com/en-us/kb/2999197

10. DBCC CHECKDB and DBCC CHECKTABLE take longer to run when SQL CLR User-Defined
type (UDT) data are involved in SQL Server 2014.

This problem occurs because SQL Server 2-14 is not reusing the internal blob memory
correctly during the validation of the SQL CLR UDT. This bug was first fixed in
Cumulative Update package 6 for SQL Server 2014. You can download the Cumulative Update
package 6 for SQL Server 2014 at here:
https://support.microsoft.com/en-us/kb/3031047

11. The error 3961 occurs when the AlwaysOn database has CLR UDT in SQL Server 2014.

This is the error message text: “Snapshot isolation transaction failed in database
‘”. This problem occurs when you run a query that involves multiple
databases that have the CLR UDT. This bug was first fixed in Cumulative Update package 7
for SQL Server 2014. You can download the Cumulative Update package 7 for SQL Server 2014
at here:
https://support.microsoft.com/en-us/kb/3046038

12. The error 6518 occurs on CLR assembly microsoft.sqlserver.types.dll in SQL Server 2014.

This is the error message text: “The process cannot access the file because it is being
used by another process”. This bug was first fixed in Cumulative Update package 9 for
SQL Server 2014. You can download the Cumulative Update package 9 for SQL Server 2014
at here:
https://support.microsoft.com/en-us/kb/3075949