Step-by-Step Guide to Solve “Execution of user code in the .NET Framework is disabled. Enable “clr” enabled configuration option”

Okay, so what’s going on here? We are using the custom “.net” code within the SQL Server. We recently migrated our database to a new server. While trying to execute the old commands on the new server, we encountered the above issue. As mentioned above, we moved our database to a new server, and it is not ready to handle .net code. To fix the issue, we need to enable CLR. The following step-by-step command will help you enable CLR on your selected SQL Server database.

Please note that before enabling it, ensure all the “.net” assemblies used within the SQL Server are from a trusted source.

Execute the following command.

Don’t enable “clr” for untrusted .net Assemblies.

As step one, we need to enable “clr” using the configuration. Execute the following command to perform the same.

Please note you may need special privileges to execute the commands. Also, please ensure you select the correct database before executing the command.

				
					USE DataBaseName
GO

EXEC sp_configure 'clr enabled', 1
GO
				
			

After executing the above command, you will get the following output.

				
					Configuration option 'clr enabled' changed from 0 to 1. Run the RECONFIGURE statement to install.

Completion time: 2024-04-13T19:13:12.9481831+05:30

				
			

As mentioned in the output next we need to execute the “RECONFIGURE” command.

				
					RECONFIGURE
GO
				
			

Output

				
					Commands completed successfully.

Completion time: 2024-04-13T19:19:09.5667460+05:30
				
			

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

				
					EXEC sp_configure 'clr enabled'
GO
				
			

Output