none
Need help "A fatal error occurred in the .NET Framework common language runtime. SQL Server is shutting down." RRS feed

  • Question

  • Microsoft SQL Server 2008 (SP2) - 10.0.4000.0 (X64)  Enterprise Edition (64-bit) on Windows NT 6.0 <X64> (Build 6002: Service Pack 2).

    Gettting this error "A fatal error occurred in the .NET Framework common language runtime. SQL Server is shutting down. If the error recurs after the server is restarted, contact Customer Support Services." repeatly.

    What are the known causes for this error on a 64Bit SQL 2008 box with SP2?   I can provide more details is necessary.

    Thanks for your help.


    Wenbin
    Tuesday, July 19, 2011 3:24 PM

Answers

  • Thank you, Bob.

    I tried to decreasing the SQL Server's 'max server memory', but the same issue still happened around the same time.   I also did tests by skipping the creation of a couple of large objects used, but the issue still happened as well.

    I did end up resolving the issue, which appears to depend on the high rate of memory allocations (object creation)  after the CLR memory usage reaching around 800MB.  

    I have some code that does string manipulations.    The code was not careful on conserving memory usage: it used the Replace method of System.String to replace some special characters without checking if the special characters exist in a string or not.    When this code was called at a very fast rate, the crash happened.

    After rewriting that piece of code,  the problem went away!  

    In summary, the issue appears to show up when the rate of memory allocation is too high (or higher than the rate of memory released by the garbage collection).

    Thanks for everyone!


    Wenbin
    • Marked as answer by Wenbin Zhang Thursday, July 21, 2011 6:41 PM
    Thursday, July 21, 2011 6:41 PM

All replies

  • Additional info about the error:

    • there are two assemblies loaded and both of them have the SAFE_ACCESS permission.
    • The following query retruns around 870000 before the crash:
    select single_pages_kb+ multi_pages_kb + virtual_memory_committed_kb 
    from sys.dm_os_memory_clerks where type = 'MEMORYCLERK_SQLCLR'

     


    Wenbin
    Tuesday, July 19, 2011 4:41 PM
  • Hi Wenbin,

    If you think the problem is caused by excessive SQLCLR memory usage, you can give SQLCLR more memory with the -g startup switch on 32-bit systems or by decreasing SQL Server's 'max server memory' option on 64-bit systems. Either will make more memory available to SQLCLR at the expense of SQL Server's buffer pool.

    You might also look into how your assemblies are managing memory for large objects. Reference http://blogs.msdn.com/b/sqlclrperf/archive/2007/06/01/scalable-memory-usage-in-sqlclr.aspx and http://technet.microsoft.com/en-us/library/ms131065(SQL.90).aspx for best practices.

    Hope this helps, Cheers, Bob

    Tuesday, July 19, 2011 4:58 PM
    Moderator
  • Thank you, Bob.

    I tried to decreasing the SQL Server's 'max server memory', but the same issue still happened around the same time.   I also did tests by skipping the creation of a couple of large objects used, but the issue still happened as well.

    I did end up resolving the issue, which appears to depend on the high rate of memory allocations (object creation)  after the CLR memory usage reaching around 800MB.  

    I have some code that does string manipulations.    The code was not careful on conserving memory usage: it used the Replace method of System.String to replace some special characters without checking if the special characters exist in a string or not.    When this code was called at a very fast rate, the crash happened.

    After rewriting that piece of code,  the problem went away!  

    In summary, the issue appears to show up when the rate of memory allocation is too high (or higher than the rate of memory released by the garbage collection).

    Thanks for everyone!


    Wenbin
    • Marked as answer by Wenbin Zhang Thursday, July 21, 2011 6:41 PM
    Thursday, July 21, 2011 6:41 PM