SQL Error – The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE
Today after setting up a new Database environment I ran into a small issue. While running a Stored Procedure I was getting following error:
Sql Severity : 16
Sql Message ID : 10314
Message
Executed as user: XYZdomain\XYZaccount. 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. For more information about this error: System.IO.FileLoadException: Could not load file or assembly ‘XYZAssemblyName, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. An error relating to security occurred. (Exception from HRESULT: 0x8013150A) System.IO.FileLoadException: at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.Load(String assemblyString) [SQLSTATE 42000] (Error 10314). The step failed.
I checked online and found that after restoring the Databases on DEV from PROD environment, the Stored Procedure that I was executing on DEV was CLR enabled thus it has the external_access or unsafe permission set from the database. And the login that was use to create the database on PROD was not same as in the instance of DEV DB. Thus it was not allowing to execute the CLR SP and resulting into error due to safety concerns.
Thus you can either use the Windows login or the SQL Server login which is common on both the environments (PROD & DEV, in my case), so:
1. First Enable Trustworthy database property
2. And change the database owner to ‘sa’
ALTER DATABASE [DatabaseName] SET TRUSTWORTHY ON; GO USE [DatabaseName] GO EXEC sp_changedbowner 'sa' GO
This issue could also occur when you are Creating a new Assembly that has the external_access or unsafe permission set in the same database.
Server: Msg 10327, Level 14, State 1, Line 1
CREATE ASSEMBLY for assembly ‘XYZAssemblyName’ failed because assembly ‘XYZAssemblyName’ 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.
Thank you, setting Database trustworthy to ‘ON’ resolved my issue.
OMG thank you sooooo much
I deleted the SPs and DLL from the server and reinstalled – worked a treat – issue had come from restore. Your post is the first post that highlighted this as a possible issue, thank you 🙂
Issue :”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.”
we were facing the above mentioned issue while deploying SSIS package
Solution:
1) use [SSISDB] select * from sys.assemblies where assembly_id=65536
as a result you will have assembly “ISSERVER”(assembly _name).
2) Delete “SSISDB” from “Integration Services Catalogs”
3) Right click on “Integration Services Catalog” then select “Create New Catalog”
4)set a password and click okay.
These steps will create assemblies under SSISDB=>Programmabilities =>assemblies
Now your good to deploy SSIS Packages. 🙂
Regards,
Pranay Chonkar
Setting Database property Trustworthy (on) worked
thank you
Kishore Agnihotram
Setting trustworthy to ON is a BAD IDEA! Another thing to check are the securables of the ##MS_SQLEnableSystemAssemblyLoadingUser## login. In our case the Unsafe Assembly right had vanished.
OMG thank you so much…. i was in panic mode, this resolved my trouble too
Pranay Chonkar your advice resolved the issue. Thank you!
Thank you! It help fixing Configuration Manager connection issue after the database restore.