c# - 部署失败 : CLR Trigger

标签 c# sql-server triggers

我正在尝试部署基于 .Net 4.0 构建的 CLR 触发器,但将目标框架更改为 3.0,但我收到以下错误消息。

------ Deploy started: Project: ServiceClient, Configuration: Debug Any CPU ------ Build started 18/01/2012 2:16:24 PM. SqlClrDeploy: Beginning deployment of assembly ServiceClient.dll to server WS037298 : custDB The following error might appear if you deploy a SQL CLR project that was built for a version of the .NET Framework that is incompatible with the target instance of SQL Server: "Deploy error SQL01268: CREATE ASSEMBLY for assembly failed because assembly failed verification". To resolve this issue, open the properties for the project, and change the .NET Framework version. Deployment script generated to: D:\Visual Studio 2010\Projects\ServiceClient\ServiceClient\bin\Debug\ServiceClient.sql

Creating [ServiceClient]... D:\Visual Studio 2010\Projects\ServiceClient\ServiceClient\bin\Debug\ServiceClient.sql(39-39): Deploy error SQL01268: .Net SqlClient Data Provider: Msg 6503, Level 16, State 12, Line 1 Assembly 'system.servicemodel, version=3.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.' was not found in the SQL catalog. An error occurred while the batch was being executed.

Build FAILED.

Time Elapsed 00:00:24.64 ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ========== ========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========

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;

        }

    }

最佳答案

明确说明 - 它需要未提供的 System.ServiceModel 程序集。首先尝试将此程序集(可能还有其他一些)部署到 sql server

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

如果您将程序集标记为 UNSAFE 并将数据库标记为 TRUSTWORTHY - 它可以在没有这些修改的情况下工作

关于c# - 部署失败 : CLR Trigger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8904760/

相关文章:

MySQL 触发器 - 在更新条件下插入

c# - 从浏览器调用Windows服务

c# - Xamarin iOS 您的应用程序正在使用需要 xamarin.ios 商业版的编译器选项

c# - 如何使异步方法返回值?

sql-server - 不能使用 LONG 数据类型

SQL Server : Select and count

sql - SQL Server 2012中如何查询最新记录?

PostgreSQL 触发器阻止另一个触发器工作

c# - 复制并粘贴到DataGridView单元格(C#)

sql-server - 触发器的 SQL if update() 语句