如何使这个2005年CLR的工作? [英] How to make this CLR work with 2005?

查看:311
本文介绍了如何使这个2005年CLR的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个CLR存储过程使用.NET 3.5组件

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

所以,首先我不得不改变SQL 2005识别系统中的SQL 2005数据库。核心为不安全的东西我不是太高兴(我宁愿有它说SAFE)。

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).

现在我得到这个错误

 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 did not know how to pass in a datetime into it so I used a string then converted it.

推荐答案

要得到这个工作,你必须将其设置为不安全的。

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

显然,一些的TimeZoneInfo方法具有 HostProtectionAttribute设定这意味着它们不能在SQL Server CLR代码中使用。

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...

这篇关于如何使这个2005年CLR的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆