我正在尝试为使用 .net 3.5 程序集的 sql 2005 数据库创建一个 clr 存储过程
因此,首先我必须更改 sql 2005 以将 system.core 识别为不安全的,这是我不太满意的(我宁愿让它说安全)。
现在我得到这个错误
Msg 6522, Level 16, State 1, Procedure StoredProcedure1, Line 0
A .NET Framework error occurred during execution of user defined routine or aggregate 'StoredProcedure1':
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:
at StoredProcedures.StoredProcedure1(String UtcDateTime)
这是我的代码
Exec StoredProcedure1 '7/8/2010 5:00:00 am'
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void StoredProcedure1(string UtcDateTime)
{
SqlPipe p = SqlContext.Pipe;
DateTime converted = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(Convert.ToDateTime(UtcDateTime), "Pacific Standard Time");
p.Send(converted.ToString());
}
};
我不知道如何将日期时间传递给它,所以我使用了一个字符串然后对其进行了转换。