c# - 系统.安全.HostProtectionException : Attempted to perform an operation that was forbidden by the CLR host

标签 c# .net sql-server multithreading sqlclr

我在我的 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()

最佳答案

此错误,如您在其他问题中所述,Deploying SQLCLR project fails when creating assembly in database , 需要满足以下条件:

ALTER ASSEMBLY [AssemblyName]
   WITH PERMISSION_SET = UNSAFE;

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

关于c# - 系统.安全.HostProtectionException : Attempted to perform an operation that was forbidden by the CLR host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28269682/

相关文章:

c# - 如何评估 c#/.net 中的数学表达式

.net - Windows 操作系统和内存管理——应用程序最小化时会发生什么?

javascript - 使用 Javascript 转换 JSON 日期

c# - 将数据插入带有文本框的数据库表

sql-server - 在 ORDER BY 子句中无效,因为它不包含在聚合函数或 GROUP BY 子句中

c# - 带动画的多重触发

c# - 仅当在 c# 中的单词开头找到时才替换字母

c# - 值类型和引用类型问题

c# - 十进制数据类型在需要显示时去除尾随零

c# - 在 C# 中,如何在不使用空格填充的情况下对上传的照片进行平方?