Assemblies in SQL Server keep unloading and loadin

2019-02-25 04:09发布

问题:

SQL Server keeps loading and unloading my Assemblies, marking them as unsafe. Any ideas why it would do that.

I am attaching the log file down below.

回答1:

The Assemblies are being unloaded due to the exact reason stated in the log: memory pressure. There is nothing specific you can do to prevent that (i.e. no option to disable this behavior). The most you can do is reduce the chances of it happening by adding more memory and/or reducing the memory consumption of your queries and/or SQLCLR objects.

The above suggestions are not meaning that there is anything currently inefficient in either your queries or .NET code, just that if you need more memory, you either need to add more or use less of it. And if you are currently using as little as possible, then you pretty much need to add more memory.

Without seeing your .NET code, it is not possible to determine if there are any areas that could be improved. However, it is more likely that the issue is outside of your SQLCLR code. You need to determine how much memory you have and where it is being used. Try looking through this Question on DBA.StackExchange:

SQL Server 2012 memory consumption outside the buffer pool

Also, SQL Server is not marking the Assembly as UNSAFE. That is simply how you have the Assembly set. You might try altering the Assembly to instead be EXTERNAL_ACCESS if it really is only doing file system access operations.