Few days ago, I got a Sql Server error using a database with a CLR assembly installed.

Running my application I got the following error:

“An error occurred in the Microsoft .NET Framework while trying to load assembly id 65536. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE. Run the query again, or check documentation to see how to solve the assembly trust issues.”

I solved the problem running these commands in Management Studio:


EXEC sp_changedbowner 'sa'

It would be nice to know why I needed to do that. The database was restored from a Sql Server 2016 instance to a Sql Server 2017 instance, and the original database didn’t have the TRUSTWORTHY option set to ON, which you can check using this query:

SELECT is_trustworthy_on FROM sys.databases WHERE name = 'MyDatabaseName';

By now I’m just happy to have solved the problem…

Bye bye