Deploy Failed : CLR Trigger

这一生的挚爱 提交于 2020-01-04 05:58:47

问题


Am trying to deploy my CLR Trigger built on .Net 4.0 but changed the target framework to 3.0 but i got the below error message.

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

        }

    }

回答1:


It is clearly stated - it wants System.ServiceModel assembly, which is not supplied. Try to deploy this assembly (and may be some others) to sql server first

And try to move your static fields into the body of trigger as local variables.

May be if you mark your assembly as UNSAFE and database as TRUSTWORTHY - it will work without these modifications



来源:https://stackoverflow.com/questions/8904760/deploy-failed-clr-trigger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!