2
votes

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
Thanks Hans, Already i did what it suggest in Humanworkflow ,still i have the problem,it look like i have to do something with my WCF - Usher
Hmm, the comment you left on Oleg's answer shows that you now got an entirely different error message. msdn.microsoft.com/en-us/library/ms403273.aspx - Hans Passant
Based on few blogs,i strongly doubt some of the assembley i have to unsafe it but whatever assembly you ask to create in "humanworkflow" its all unsafe.i have no clue which assemble i have to unsafe now to get deploy this project - Usher
Again i recheck the assembly installed in my sqlserver all are unsafe. - Usher

1 Answers

2
votes

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