部署失败:CLR触发器

时间:2012-01-18 03:21:51

标签: c# sql-server triggers

我试图在.Net 4.0上部署我的CLR触发器,但是将目标框架更改为3.0但是我收到了以下错误消息。

  

------部署已启动:项目:ServiceClient,配置:调试任何CPU ------   生成于18/01/2012 2:16:24 PM开始。   SqlClrDeploy:     开始将程序集ServiceClient.dll部署到服务器WS037298:custDB     如果部署为与.NET Server的目标实例不兼容的.NET Framework版本构建的SQL CLR项目,则可能会出现以下错误:“部署错误SQL01268:由于程序集验证失败,程序集的CREATE ASSEMBLY失败”。要解决此问题,请打开项目的属性,然后更改.NET Framework版本。     部署脚本生成为:     D:\ Visual Studio 2010 \ Projects \ ServiceClient \ ServiceClient \ bin \ Debug \ ServiceClient.sql

     

创建[ServiceClient] ...   D:\ Visual Studio 2010 \ Projects \ ServiceClient \ ServiceClient \ bin \ Debug \ ServiceClient.sql(39-39):部署错误SQL01268:.Net SqlClient数据提供程序:消息6503,级别16,状态12,行1程序集'系统.servicemodel,version = 3.0.0.0,culture = neutral,publickeytoken = b77a5c561934e089。在SQL目录中找不到。     批处理执行时发生错误。

     

构建失败。

     

时间流逝00:00:24.64   ==========构建:1成功或最新,0失败,0跳过==========   ==========部署:0成功,1失败,0跳过==========

public partial class Triggers
{
    //Create an endpoint addresss for our serivce
    public static EndpointAddress endpoint =
      new EndpointAddress(new Uri("http://localhost:8000/services/myservice"));
    //Create a binding method for our service
    public static WSHttpBinding httpBinding = new WSHttpBinding();
    //Create an instance of the service proxy
    public static ServiceClient.ServiceReference1.ServiceContractClient myclient = new ServiceClient.ServiceReference1.ServiceContractClient(httpBinding, endpoint);
//    public static ServiceClient.localhost.ServiceContractClient myClient = new ServiceClient.localhost.ServiceContractClient(httpBinding, endpoint);
    //A delegate that is used to asynchrounously talk
    //to the service when using the FAST METHOD
    public delegate void MyDelagate(String crudType);


    [SqlProcedure()]
    public static void SendData(String crudType)
    {

        /*A very simple procedure that accepts a string parameter 
          based on the CRUD action performed by the
          trigger. It switches based on this parameter 
          and calls the appropriate method on the service proxy*/

        switch (crudType)
        {
            case "Update":

                myclient.UpdateOccured();

                break;

            case "Insert":

                myclient.InsertOccured();
                break;
        }

    }

    [Microsoft.SqlServer.Server.SqlTrigger(Name = "WCFTrigger",
       Target = "tbCR", Event = "FOR UPDATE, INSERT")]
    public static void Trigger1()
    {
        /*This is a very basic trigger that performs two very simple actions:
         * 1) Gets the current trigger Context
         *    and then switches based on the triggeraction
         * 2) Makes a call to a stored procedure

         * Two methods of calling the stored procedure are presented here. 
         * View the article on Code Project for a discussion on these methods
         */

        SqlTriggerContext myContext = SqlContext.TriggerContext;
        //Used for the FAST METHOD
        MyDelagate d;

        switch (myContext.TriggerAction)
        {
            case TriggerAction.Update:

                //Slow method - NOT REMCOMMEND IN PRODUCTION!
                SendData("Update");

                //Fast method - STRONGLY RECOMMENDED FOR PRODUCTION!
                //d = new MyDelagate(SendData);
                //d.BeginInvoke("Update",null,null);

                break;

            case TriggerAction.Insert:

                //Slow method - NOT REMCOMMEND IN PRODUCTION!
                SendData("Insert");

                //Fast method - STRONGLY RECOMMENDED FOR PRODUCTION!
                //d = new MyDelagate(SendData);
                //d.BeginInvoke("Insert", null, null);

                break;

        }

    }

1 个答案:

答案 0 :(得分:2)

明确说明 - 它需要System.ServiceModel程序集,它不提供。尝试首先将此程序集(可能是其他程序集)部署到SQL Server

并尝试将静态字段作为局部变量移动到触发器体中。

如果您将程序集标记为UNSAFE而数据库标记为TRUSTWORTHY,则可能会在没有这些修改的情况下生效