SQL Server 2008 - What is an easy way to check if clr is enabled?
6 Answers
SELECT * FROM sys.configurations
WHERE name = 'clr enabled'
-
30
-
Check the config_value
in the results of sp_configure
You can enable CLR by running the following:
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
-
5I don't think you should actually configure the option just to check if it's configured! I realize it will say
was 0 now 1
, or similar, but ...– Josh M.Apr 17, 2014 at 20:11
The accepted answer needs a little clarification. The row will be there if CLR is enabled or disabled. Value will be 1 if enabled, or 0 if disabled.
I use this script to enable on a server, if the option is disabled:
if not exists(
SELECT value
FROM sys.configurations
WHERE name = 'clr enabled'
and value = 1
)
begin
exec sp_configure @configname=clr_enabled, @configvalue=1
reconfigure
end
-
1EXISTS() is slightly faster than NOT EXISTS(). Just a friendly note. ;) Apr 26, 2017 at 14:02
-
4in this case imho readability trumps performance, which for a single shot dba usage like this would be infinitesimal. May 10, 2017 at 17:33
The correct result for me with SQL Server 2017:
USE <DATABASE>;
EXEC sp_configure 'clr enabled' ,1
GO
RECONFIGURE
GO
EXEC sp_configure 'clr enabled' -- make sure it took
GO
USE <DATABASE>
GO
EXEC sp_changedbowner 'sa'
USE <DATABASE>
GO
ALTER DATABASE <DATABASE> SET TRUSTWORTHY ON;
From An error occurred in the Microsoft .NET Framework while trying to load assembly id 65675
This is @Jason's answer but with simplified output
SELECT name, CASE WHEN value = 1 THEN 'YES' ELSE 'NO' END AS 'Enabled'
FROM sys.configurations WHERE name = 'clr enabled'
The above returns the following:
| name | Enabled |
-------------------------
| clr enabled | YES |
Tested on SQL Server 2017