Home > Uncategorized > SQL Error – The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE

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.


Advertisement
  1. Bhargav Lalisetti
    November 27, 2018 at 10:02 pm

    Thank you, setting Database trustworthy to ‘ON’ resolved my issue.

  2. David
    May 21, 2019 at 6:27 pm

    OMG thank you sooooo much

  3. IssueResolved
    July 3, 2019 at 7:07 pm

    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 🙂

  4. Pranay Chonkar
    August 29, 2019 at 3:00 pm

    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

  5. Kishore Agnihotram
    September 4, 2019 at 8:48 pm

    Setting Database property Trustworthy (on) worked
    thank you
    Kishore Agnihotram

  6. Ronald
    December 24, 2019 at 4:36 pm

    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.

  7. Andrew
    April 28, 2020 at 1:54 am

    OMG thank you so much…. i was in panic mode, this resolved my trouble too

  8. Ed Polley
    August 5, 2020 at 3:20 am

    Pranay Chonkar your advice resolved the issue. Thank you!

  9. Savo Jovanovic
    March 3, 2023 at 2:57 am

    Thank you! It help fixing Configuration Manager connection issue after the database restore.

  1. December 31, 2020 at 2:37 pm
  2. January 3, 2022 at 10:55 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: