【问题标题】:SQL Server: How to check if CLR is enabled?SQL Server:如何检查是否启用了 CLR?
【发布时间】:2011-06-15 20:21:00
【问题描述】:

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

【问题讨论】:

    标签: sql sql-server clr


    【解决方案1】:
    SELECT * FROM sys.configurations
    WHERE name = 'clr enabled'
    

    【讨论】:

    • 附加说明:启用时值为 1,禁用时值为 0。
    • 这在 SQL 2016 中仍然有效。
    【解决方案2】:

    检查sp_configure结果中的config_value

    您可以通过运行以下命令来启用 CLR:

    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

    【讨论】:

    • 我认为您不应该仅仅为了检查它是否已配置而实际配置该选项!我知道它会说was 0 now 1,或者类似的,但是...
    【解决方案3】:

    接受的答案需要一点澄清。如果启用或禁用 CLR,该行将在那里。如果启用,则值为 1,如果禁用,则值为 0。

    如果该选项被禁用,我使用此脚本在服务器上启用:

    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
    

    【讨论】:

    • EXISTS() 比 NOT EXISTS() 稍快。只是一个友好的说明。 ;)
    • 在这种情况下,恕我直言,可读性胜过性能,对于像这样的单次 dba 使用而言,性能将是无限小的。
    【解决方案4】:
    select *
    from sys.configurations
    where name = 'clr enabled'
    

    【讨论】:

      【解决方案5】:

      对我来说使用 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;  
      

      来自An error occurred in the Microsoft .NET Framework while trying to load assembly id 65675

      【讨论】:

        【解决方案6】:

        这是@Jason 的答案,但输出经过简化

        SELECT name, CASE WHEN value = 1 THEN 'YES' ELSE 'NO' END AS 'Enabled'
        FROM sys.configurations WHERE name = 'clr enabled'
        

        以上返回如下:

        | name        | Enabled |
        -------------------------
        | clr enabled | YES     |
        

        在 SQL Server 2017 上测试

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-04-12
          • 1970-01-01
          • 1970-01-01
          • 2019-02-09
          • 2017-12-24
          • 1970-01-01
          相关资源
          最近更新 更多