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

mab*_*rei 6 .net sql-server

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

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

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)
Run Code Online (Sandbox Code Playgroud)

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

有谁知道我必须设置什么才能使这个工作或我可能做错了什么?

gbn*_*gbn 11

CLR程序集具有信任级别.

这个需要UNSAFE权限,因为使用"MayLeakOnAbort"所需的权利

将CLR更改为更安全的内容,或者使用UNSAFE权限重新添加程序集."UNSAFE"这个词当然是......