SQLServer: 如何检查 CLR 是否已启用?

SQLServer2008-检查 clr 是否启用的简单方法是什么?

125758 次浏览
SELECT * FROM sys.configurations
WHERE name = 'clr enabled'

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

select *
from sys.configurations
where name = 'clr enabled'

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

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