How to resolve Geospatial Data over linked server causing error? Update of the issue.

The exact error is Failed to initialize the Common Language Runtime (CLR) v2.0.50727 with HRESULT 0x80131022. You may fix the problem and try again later.

The error is happening on my local instance of SQL Server 2008r2 in a sp that calls a linked server (another sql server 2008r2) via an OPENQUERY call. I am executing that sp from my local instance. The code that calls the linked server fails but only when geospatial data (geometry) is included in the select part of the statement( the statement called in the open query.) When there is no geospatial data in the select statement to the linked server it executed fine. So geospatial data over a linked server connceting causes the error.

I should point out, but this may be a red herring, that the same stored procedure was called from an sql task in an ssis package and it passed. It called the procedure on my local instance of sql server. But that is not the issue now. The issue is outlined above.

I should also point out that Microsoft called that particular error a Memory Pressure error.
The "memory" being referred to in the term "memory pressure" is physical RAM, not hard-drive space.

What exactly are you attempting to do when you get this error? It seems that it could be due to attempting to invoke CLR code from within an sp_OA* OLE-Automation stored procedure call. That is documented in the following Microsoft forum thread: CLR initialization failed with hresult 0x80131022.

According to the following Microsoft KB article (# 2003681), it could be due to actual memory pressure: Possible causes of "Failed to initialize the Common Language Runtime (CLR)" when using SQL CLR. Memory pressure refers to running low on physical RAM as that is what SQL Server prefers to use. For doing stuff in SQLCLR, these types of errors were much more common prior to SQL Server 2012, especially on 32-bit systems. Are you on a 32-bit system?

Also, in this Microsoft forum thread (related to SQL Server 2008 R2) -- Failed to enter Common Language Runtime (CLR) with HRESULT 0x80131022. This may due to low resource conditions -- Bob Beauchemin states:


  You can increase the amount of memory available to SQLCLR on 64-bit systems by decreasing SQL Server's max_server_memory setting. You can monitor the amount of memory used by SQLCLR with a sum of sys.dm_os_memory_objects where type like '%CLR%' and the appropriate perfmon counters in the .NET CLR memory series.


For more information on SQL Server memory architecture (for SQL Server 2005, 2008, and 2008 R2), please see the following articles:


Basics of SQL Server Memory Architecture (by Karthick P.K)
Understanding the VAS Reservation (aka MemToLeave) in SQL Server (by Jonathan Kehayias)