如何让这个 CLR 与 2005 一起工作?

发布于 2024-09-08 17:33:44 字数 1290 浏览 3 评论 0原文

我正在尝试为使用 .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());

    }
};

我不知道如何将日期时间传递给它,所以我使用了一个字符串然后将其转换。

I am trying to make a clr stored procedure for a sql 2005 database that uses .net 3.5 assemblies

So first I had to change sql 2005 to recognize system.core as unsafe what I am not too happy about(I rather have had it say SAFE).

Now I get this error

 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)

Here is my code

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

    }
};

I did not know how to pass in a datetime into it so I used a string then converted it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一腔孤↑勇 2024-09-15 17:33:44

为了让它工作,你必须将其设置为不安全。

显然,某些 TimeZoneInfo 方法设置了 HostProtectionAttribute,这意味着它们不能在 SQL Server CLR 代码中使用。

除非你决定“我不关心稳定性并且更了解”。如果您使用 UNSAFE,如果您的服务器变成冒烟的坑,我不承担任何责任...

To get this to work you'd have to set it as UNSAFE.

Apparently, some TimeZoneInfo methods have HostProtectionAttribute set which means they can't be used in SQL Server CLR code.

Unless you decide "I don't care about stability and know better". I take no responsibility if your server becomes a smoking crater in the ground if you use UNSAFE...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文