2

.net3.5アセンブリを使用するSQL2005データベースのclrストアドプロシージャを作成しようとしています

そのため、最初にsql 2005を変更して、system.coreを安全ではないと認識し、あまり満足していないことを認識しなければなりませんでした(むしろ、SAFEと言ってもらいました)。

今、私はこのエラーを受け取ります

 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());

    }
};

日時を渡す方法がわからなかったので、文字列を使用して変換しました。

4

1 に答える 1

6

これを機能させるには、UNSAFEとして設定する必要があります。

どうやら、一部のTimeZoneInfoメソッドにはHostProtectionAttributeが設定されているため、SQLServerCLRコードでは使用できません。

あなたが「私は安定性を気にせず、よく知っている」と決めない限り。UNSAFEを使用した場合、サーバーが地上で喫煙クレーターになった場合、私は責任を負いません...

于 2010-07-09T06:24:09.933 に答える