【问题标题】:System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR hostSystem.Security.HostProtectionException:尝试执行 CLR 主机禁止的操作
【发布时间】:2015-02-02 00:43:51
【问题描述】:

我在我的 SQLCLR 项目中使用线程,当我尝试运行我的用户定义函数时出现以下错误。如何在我的项目中启用线程处理,例如并行库和等待/异步?

消息 6522,第 16 级,状态 1,第 4 行
在执行用户定义的例程或聚合“CalculateInfo”期间发生 .NET Framework 错误:
System.Security.HostProtectionException:尝试执行 CLR 主机禁止的操作。

    受保护的资源(仅在完全信任的情况下可用)是:所有
所需资源是:同步、外部线程

   System.Security.HostProtectionException:
在 UserDefinedFunctions.getData()
在 UserDefinedFunctions.CalculateInfo()

【问题讨论】:

    标签: c# .net sql-server multithreading sqlclr


    【解决方案1】:

    正如您在另一个问题Deploying SQLCLR project fails when creating assembly in database 中所述,此错误需要以下内容:

    ALTER ASSEMBLY [AssemblyName]
       WITH PERMISSION_SET = UNSAFE;
    

    有关使用 SQLCLR 的更多信息,请访问:SQLCLR Info

    【讨论】:

      【解决方案2】:

      将 Premission 集字段值设置为 Unrestricted。

      【讨论】:

        猜你喜欢
        • 2011-05-15
        • 1970-01-01
        • 1970-01-01
        • 2021-08-01
        • 2011-07-07
        • 1970-01-01
        • 2012-04-14
        • 2012-12-25
        • 2014-02-12
        相关资源
        最近更新 更多