Tara Kizer Blog

Tara Kizer

Fix for CLR object execution error after attach/restore in SQL Server 2005

After attaching or restoring a database to SQL Server 2005, you may encounter an error when executing a CLR object. 

Error:

An error occurred in the Microsoft .NET Framework while trying to load assembly id 65538. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE.

This KB article describes the issue and shows the fix, however it says the bug occurs when the database is attached/restored to a different SQL instance.  I’ve encountered the error three times now.  In at least one occurrence of the error, it has happened when I’ve restored the database to the same SQL instance.

Fix:

USE master
GO
ALTER DATABASE dbNameGoesHere SET TRUSTWORTHY ON

USE dbNameGoesHere GO EXEC sp_changedbowner 'sa'


Legacy Comments


Nitin
2009-10-02
re: Fix for CLR object execution error after attach/restore in SQL Server 2005
Its also noteworthy that while one backup the database containing CLR objects and restores it, the listed command needs to be executed with reference to new database in order to run/execute CLR function/s successfully


Nitin
2009-10-02
re: Fix for CLR object execution error after attach/restore in SQL Server 2005
Even on same instance, we need to run listed command when database is backed up