99

SQL Server 2008 - What is an easy way to check if clr is enabled?

magnattic
  • 12,638
  • 13
  • 62
  • 115

6 Answers6

149
SELECT * FROM sys.configurations
WHERE name = 'clr enabled'
Jason
  • 4,557
  • 5
  • 31
  • 40
38

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

MSDN Article on enabling CLR

MSDN Article on sp_configure

codingbadger
  • 42,678
  • 13
  • 95
  • 110
  • 6
    I 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 '14 at 20:11
29

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
Larry Smith
  • 1,863
  • 16
  • 15
3
select *
from sys.configurations
where name = 'clr enabled'
grapefruitmoon
  • 2,988
  • 1
  • 22
  • 26
3

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

halfer
  • 19,824
  • 17
  • 99
  • 186
Sayed Abolfazl Fatemi
  • 3,678
  • 3
  • 36
  • 48
2

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

spicy.dll
  • 948
  • 8
  • 23