.net - 在 SQL Server 上执行用户定义函数时出现 System.Security.HostProtectionException

标签 .net sql-server

我编写了一个用户定义函数,它获取 UtcTimeStamp 和 windowstimezoneid 作为参数,并返回 TimeZone 的时间戳。

但是如果我想在一个简单的选择中执行它,我会收到以下错误:

A .NET Framework error occurred during execution of user-defined routine or aggregate "ToLocalTime": 
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: MayLeakOnAbort

System.Security.HostProtectionException: 
   bei TimeFunctions.ToLocalTime(DateTime UtcTimestamp, String WindowsTimeZoneId)

我将 select 作为 sa 执行。我将 clr 启用设置为 1。我使用 SQL Server 2008 R2 (10.50.1600)。

有谁知道我必须设置什么才能使其正常工作或者我可能做错了什么?

最佳答案

CLR 程序集有 trust levels.

此权限需要 UNSAFE 权限,因为需要使用“MayLeakOnAbort”的权限

要么将 CLR 更改为更安全的内容,要么重新添加具有 UNSAFE 权限的程序集。 “不安全”这个词当然就是这个意思......

关于.net - 在 SQL Server 上执行用户定义函数时出现 System.Security.HostProtectionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6568751/

相关文章:

c# - 为什么这个自定义的 Word 后台 UI 不显示其用户界面?

mysql - 如何将 mysql 查询转换为事务 SQL 查询

SQL明显排列列查询问题

.Net 代码库元素

c# - SQL注入(inject)漏洞

c# - 在 asp.net core 中使用 NVarChar

sql - 按范围分组 SQL Server

c# - wpf 应用程序中的自定义组合框选定文本

c# - Winforms WPF Interop - WPF 内容无法绘制

c# - 如何在 C# 中存储之前验证 .csv 文件?