Hi friends, in this article, we will be discussing about, how to resolve the below error, when working with CLR assemblies in SQL Server:
An error occurred in the Microsoft .NET Framework while trying to load assembly id… The server may be running out of resources, or the assembly may not be trusted. 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 …
How to Resolve the Issue
In order to resolve the issues, there is a series of steps that you can try.
Step 1: Check if CLR is Enabled in the SQL Server Instance
The first thing to check, which is quite obvious, is whether CLR is enabled or not, in the specific SQL Server instance.
In order to check this, you just need to run in SSMS the below T-SQL statement:
sp_configure 'clr enabled'; GO
In the “run_value” is set to 1, it means that CLR is indeed enabled.
If it is not enabled and you have the approval to indeed enable it, you can do so, using the below T-SQL statements:
sp_configure 'clr enabled',1; GO RECONFIGURE WITH OVERRIDE; GO
Step 2: Check the CLR Assembly File Path References
The next step, is to check the CLR assemblies that are loaded into the SQL Server instance.
To do so, you need to run the following SELECT T-SQL statement:
SELECT * FROM sys.assembly_files; GO
Based on the query results, you should make sure that the assemblies listed, are indeed located in the referenced file path.
If a reference assembly file (dll) is missing, then that’s the problem and you need to register again the assembly (step 4a).
Step 3: Check the Loaded Assemblies
The next step, is to check the CLR assemblies that are loaded into the SQL Server instance.
To do so, you need to run the following SELECT T-SQL statement:
SELECT * FROM sys.dm_clr_loaded_assemblies; GO
If the above query does not return anything, then bingo, you just found the problem!
So, in this case, it means that your CLR assembly is not properly registered and you need to refresh it (step 4b).
Step 4a: Registering the CLR Assembly Again in SQL Server
So, if the issue was identified in Step 2, then it means you need to re-register the specific CLR assembly in SQL Server.
To this, you can run the following T-SQL statement:
--Recommendation: Only use CLR Assemblies with SAFE permissions CREATE ASSEMBLY [ASSEMBLY_NAME] FROM 'path to assembly .dll file' WITH PERMISSION_SET = [SET THE PERMISSION SET HERE: SAFE, UNSAFE OR EXTERNAL]
Step 4a: Refreshing the CLR Assembly in SQL Server
So, if the issue was identified in Step 3, then it means you need to refresh the specific CLR assembly in SQL Server.
To this, you can run the following T-SQL statement:
ALTER ASSEMBLY [ASSEMBLY_NAME] FROM 'path to .dll file'; GO
Learn more about SQL Server Development – Enroll to our Course!
Enroll to our online course titled “Essential SQL Server Development Tips for SQL Developers” (special limited-time discount included in link) and sharpen your SQL Server database programming skills via a large set of tips on T-SQL and database development techniques. The course, among other, features over than 30 live demonstrations!
Featured Online Courses:
- SQL Server 2022: What’s New – New and Enhanced Features
- Working with Python on Windows and SQL Server Databases
- Introduction to Azure Database for MySQL
- Boost SQL Server Database Performance with In-Memory OLTP
- Introduction to Azure SQL Database for Beginners
- Essential SQL Server Administration Tips
- SQL Server Fundamentals – SQL Database for Beginners
- Essential SQL Server Development Tips for SQL Developers
- Introduction to Computer Programming for Beginners
- .NET Programming for Beginners – Windows Forms with C#
- SQL Server 2019: What’s New – New and Enhanced Features
- Entity Framework: Getting Started – Complete Beginners Guide
- Data Management for Beginners – Main Principles
- A Guide on How to Start and Monetize a Successful Blog
Read Also:
- Essential SQL Server Development Tips for SQL Developers (Course Preview)
- Resolve SQL Server CTE Error – Incorrect syntax near ‘)’.
- The TempDB System Database in SQL Server
- SQL Server Installation and Setup Best Practices
- The feature you are trying to use is on a network resource that is unavailable
- SQL Server 2016: TempDB Enhancements
- tempdb growth
- Introduction to SQL Server Machine Learning Services
- Essential SQL Server Administration Tips
- What are SQL Server Statistics and Where are they Stored?
- Tip of the Week No.1 – SQL Server Always Encrypted
- Tip of the Week No.3 – TempDB Settings During Installation
- Tip of the Week No.6 – About SQL Server Temporary Tables
- Tip of the Week No.19 – What is the Database First Workflow in Entity Framework?
- Tip of the Week No.20 – SQL Server Surface Area
- Within Which Context Does SQL Server Access Network Resources?
- Troubleshooting the File Activation Error in SQL Server
Subscribe to our newsletter and stay up to date!
Subscribe to our YouTube channel (SQLNetHub TV)
Check our eBooks!
Rate this article:
Reference: SQLNetHub.com (https://www.sqlnethub.com)
© SQLNetHub
Artemakis Artemiou is a seasoned Senior Database and AI/Automation Architect with over 20 years of expertise in the IT industry. As a Certified Database, Cloud, and AI professional, he has been recognized as a thought leader, earning the prestigious Microsoft Data Platform MVP title for nine consecutive years (2009-2018). Driven by a passion for simplifying complex topics, Artemakis shares his expertise through articles, online courses, and speaking engagements. He empowers professionals around the globe to excel in Databases, Cloud, AI, Automation, and Software Development. Committed to innovation and education, Artemakis strives to make technology accessible and impactful for everyone.