System.Security.HostProtectionException: 试图执行 CLR 主机禁止的操作

System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host

我在 SQLCLR 项目中使用线程,当我尝试 运行 我的用户定义函数时出现以下错误。我可以做些什么来在我的项目中启用并行库和 await/async 等线程?

Msg 6522, Level 16, State 1, Line 4
A .NET Framework error occurred during execution of user-defined routine or aggregate "CalculateInfo":
  System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host.

    The protected resources (only available with full trust) were: All
    The demanded resources were: Synchronization, ExternalThreading

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

如您在另一个问题 中所述,此错误需要以下条件:

ALTER ASSEMBLY [AssemblyName]
   WITH PERMISSION_SET = UNSAFE;

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

将权限集字段值设置为不受限制。