THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

The Rambling DBA: Jonathan Kehayias

The random ramblings and rantings of frazzled SQL Server DBA

CLR Safety Issues After Database Restore to New Server

While working on finalizing the installation and configuration of SQL 2005 on a test server that I plan to upgrade to SQL 2008 Feb CTP, I ran into a snag. In order to test all the different Upgrade paths that would affect me, I have built a test server with:
  1. Three Databases, one in 90 compatiblity, one in 80 compatibility, and one in Full Recovery.
  2. A Linked Server to Oracle.
  3. A SSIS Package that pulls data with a Data
  4. A CLR Assembly
  5. A Reports Server with all of our Reports in it
  6. A current Analysis Cube that we are building out.

However, when I was validating everythings functionality in SQL 2005 before the upgrade I found that I couldn't run any of the CLR functions in the Assembly, I kept getting errors like I would if the database was not set TRUSTWORTHY ON. Something like:

Msg 10314, Level 16, State 11, Line 1
An error occurred in the Microsoft .NET Framework while trying to load assembly id 65560. 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. For more information about this error:
System.IO.FileLoadException: Could not load file or assembly 'sqlserverproject1, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An error relating to security occurred. (Exception from HRESULT: 0x8013150A)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)

At first, I figured no problem, I have the source, I will just redeploy it, but I couldn't do that. I kept getting the standard error message letting me know TRUSTWORTHY was not ON, even though it was:

Server: Msg 10327, Level 14, State 1, Line 1CREATE ASSEMBLY for assembly 'sqlserverproject1' failed because assembly 'sqlserverproject1' is not authorized for PERMISSION_SET = EXTERNAL_ACCESS. The assembly is authorized when either of the following is true: the database owner (DBO) has EXTERNAL ACCESS ASSEMBLY permission and the database has the TRUSTWORTHY database property on; or the assembly is signed with a certificate or an asymmetric key that has a corresponding login with EXTERNAL ACCESS ASSEMBLY permission.

After validating that TRUSTWORTHY was ON, restarting services, checking surface configuration to ensure it was enabled, and spending an hour searching online, I found the following article.

You may receive an error message when you try to run an existing CLR object or create an assembly that has the external_access or unsafe permission set on a database that is attached or restored from a different server

To fix this issue, all I had to do was execute

USE [DatabaseName]
EXEC sp_changedbowner 'databaseownername'

Published Thursday, March 06, 2008 2:45 PM by Jonathan Kehayias



Grady Christie said:

Thank you for submitting.  This solved my problem after hours of research.  Grady Christie

July 9, 2009 10:43 AM
Anonymous comments are disabled

This Blog


Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement