我编写了一个用户定义函数,它获取 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/