Frequent Error Message: "Another query caused the AppDomain <dbname>.dbo[runtime].n to be unloaded"

John Wilber 21 Reputation points
2021-03-16T19:17:01.41+00:00

I'm currently working on SQL Server 2017 - Here's the @@version:

Microsoft SQL Server 2017 (RTM-CU20) (KB4541283) - 14.0.3294.2 (X64)
Mar 13 2020 14:53:45
Copyright (C) 2017 Microsoft Corporation  Enterprise Edition (64-bit) on Windows Server 2016 Datacenter 10.0 <X64> (Build 14393: ) 

We keep getting jobs failing with error messages very similar to this:

2021-03-16 06:11:32.7483 -07:00 Error: .NET Framework execution was aborted. Another query caused the AppDomain Market.dbo[runtime].41 to be unloaded.

It also seems that several jobs fail with this error about the same time, and they all use CLR assemblies.

Obviously, there's a memory usage issue. We don't believe there is anything wrong with the code, however, we believe the assembly that is causing the issues is one that uses the HttpClient class. The procedure that calls this assembly typically calls the CLR function about 300 times in quick succession when it's run. To further complicate things, two copies of the stored proc are run simultaneously for greater throughput, for a total of about 600 calls to the CLR assembly in a short period of time.

Does anyone have any suggestions for how we can monitor memory usage by this specific assembly?
Is there a way to allocate more memory for the CLR assemblies?
Any other suggestions as to how we can make this more reliable?

Thanks,

John

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,807 questions
{count} votes

Accepted answer
  1. CathyJi-MSFT 21,096 Reputation points Microsoft Vendor
    2021-03-17T07:43:25.007+00:00

    Hi @John Wilber ,

    > Is there a way to allocate more memory for the CLR assemblies?

    There is no CLR-specific memory allocation. What memory is available for SQLCLR objects depends on:

    • What version of SQL Server you are on. Memory allocation changed starting in SQL Server 2012.
    • How much memory is in the server
    • If there are other processes running on the server

    Quote from the similar thread How do I reduce or add memory allocation for just CLR in SQL Server?


    If the response is helpful, please click "Accept Answer" and upvote it, thank you.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Niels Berglund 11 Reputation points MVP
    2021-03-18T06:11:25.057+00:00

    Hi @John Wilber !

    Couple of questions:

    1. What do you see in the SQL Server Log at the time this error happens?
    2. In your post you say "Obviously, there's a memory usage issue.", what makes you say that?
    3. What does the code look like that that calls the HttpClient class?

    As @CathyJi-MSFT says; you cannot specifically add more memory to SQLCLR.

    Niels

    1 person found this answer helpful.