none
Error calling dtsx package from C# RRS feed

  • Question

  • Hi all, I've written a small winForm application to call a SSIS package with a configuration file.

    In addition I've added a class EventListener inherited from DefaultEvents to log execution error.

    Here you are application code:

                string pkgLocation;
                Package pkg;
                Microsoft.SqlServer.Dts.Runtime.Application app;
                DTSExecResult pkgResults;
                MyEventListener eventListener = new MyEventListener();
                pkgLocation = txtDTX.Text;
                
                app = new Microsoft.SqlServer.Dts.Runtime.Application();
                pkg = app.LoadPackage(pkgLocation, eventListener);
                pkg.ImportConfigurationFile(txtConfig.Text);
                pkgResults = pkg.Execute(null, null, eventListener,null,null);

    and this is MyEventListener class

    public class MyEventListener : DefaultEvents
        {
            public override bool OnError(DtsObject source, int errorCode, string subComponent,
         string description, string helpFile, int helpContext, string idofInterfaceWithError)
            {
                StreamWriter oFile = new StreamWriter(ConfigurationManager.AppSettings["ErrorFile"],true);
                oFile.WriteLine("Error in {0}/{1} : {2}", source, subComponent, description);
                oFile.Flush();
                oFile.Close();
                oFile.Dispose();
                return false;
            }
        }

    Running the application on a Windows Server 2008 R2 (64 bit) machine with SSIS 2012 installed (my code refers to Microsoft.SqlServer.ManagedDTS.dll version 11.0.2100.60)

    the package fails and I took the following error on my EventListener: Error in Microsoft.SqlServer.Dts.Runtime.TaskHost/ : The Execute method on the task returned error code 0x80131621 (Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.). The Execute method must succeed, and indicate the result using an "out" parameter.

    Can someone help me to investigate the problem?

    Perhaps I need to use a different way instead of MyEventListener class?

    Thank you in advance for your help.

    Best regards

    Fabrizio

    Friday, May 25, 2012 8:48 AM

Answers

  • If you need to add it to the web.config (and I have no idea if you really need to)  you can get the info from your csproj file after you included the reference.

    This is the info from my machine

     <Reference Include="Microsoft.SQLServer.ManagedDTS, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">


    Chuck Pedretti | Magenic – North Region | magenic.com


    Wednesday, May 30, 2012 1:03 PM

All replies

  • What that error is telling you is that you created a 4.0 framework project and are trying to use a 2.0 Framework assembly. 

    You need to add this to your app.config so that your 2.o mixed mode assembly can be loaded by the 4.0 framework

    <?xml version="1.0"?>
    <configuration>
     
    <startup useLegacyV2RuntimeActivationPolicy="true">
       
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
     
    </startup>
    </configuration>


    Chuck Pedretti | Magenic – North Region | magenic.com


    Friday, May 25, 2012 12:30 PM
  • Dear Chuck thank you for your reply, it works perfectly thank you.

    I've another question, I need to migrate a web page (aspx) from a Windows Server 2003 32 bit machine with Integration Services 2005 installed to new machine Windows Server 2008 R2 (64 bit) machine with SSIS 2012 installed.

    The web page programmatically calls SSIS package

        protected void Page_Load(object sender, EventArgs e)
        {
            string repository = "";
            string filename = Request.QueryString["PATHFILE"];
            string pathfile = "";
            if (filename != null){
                pathfile = repository + filename;
                bool bResult = true;
                string risultato = string.Empty;
                SSISpckManager impTL = new SSISpckManager();           
                impTL.Load(ConfigurationManager.AppSettings["IMP_ESO_TOCORR"].ToString());
                impTL.SetVariable("CONN_CM", ConfigurationManager.AppSettings["SSIS_FC_OLEDBConnection"]);
                impTL.SetVariable("LOG_DIRECTORY", ConfigurationManager.AppSettings["LOG_DIRECTORY"]);
                impTL.SetVariable("INPUT_FILE_CORR", pathfile);
                bResult = impTL.Execute(out risultato);

    In web.config there is the following assembly

    <add assembly="Microsoft.SqlServer.ManagedDTS, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>

    How can I modify web config to use newer version of Microsoft.SqlServer.ManagedDTS.dll(11.0.2100.60) ?

    Which is the correct PublicKeyToken for this dll?

    Being not registered in GAC I think I have to copy this dll in bin folder for my website.

    Is this enough or I have to perform some other steps?

    Thank you again for your precious help.

    Best regards

    Fabrizio

    Tuesday, May 29, 2012 5:06 PM
  • No need to do it manually.  Just add the reference to the solution using the browse functionality to navigate to the DLL on your hard drive.  It will then create the correct add assembly statement.  That normally also copies the dll to your project BIN directory - as long as you have the "copy local?" option set to true.

    Chuck Pedretti | Magenic – North Region | magenic.com


    Tuesday, May 29, 2012 5:31 PM
  • Dear Chuck, thank you again for your reply, I've tried your suggestion but I can't see add assembly statement in my web.config, I've performed the following steps:

    Create a new Wep Application from VS2010

    Add a reference to Microsoft.SqlServer.ManagedDTS.dll (browsing it from my file system)

    Compile with success but I can't see an add assembly statement in my web.config.

    I have another question, existing web site was created using .NET Framework 2.0, can I add a 4.0 assembly to this web site?

    Thank you again for your precious help.

    Best regards

    Fabrizio

    Wednesday, May 30, 2012 8:01 AM
  • I'm pretty sure that you can't use a 4.0 framework assembly in a 2.0 project, but that might be a better question for a .Net forum.

    Chuck Pedretti | Magenic – North Region | magenic.com

    Wednesday, May 30, 2012 12:26 PM
  • Thank you Chuck, but I can create a new website (running with .NET Framework 4) to perform the calling, anyway could you suggest me a way to identify the correct reference?

    I've tried to add a new reference in a new Web Application (target Framework 4.0) but no add assembly statement in my web.config.What's wrong?

    Thank you again for your help.

    Best regards

    Fabrizio

    Wednesday, May 30, 2012 12:44 PM
  • If you need to add it to the web.config (and I have no idea if you really need to)  you can get the info from your csproj file after you included the reference.

    This is the info from my machine

     <Reference Include="Microsoft.SQLServer.ManagedDTS, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">


    Chuck Pedretti | Magenic – North Region | magenic.com


    Wednesday, May 30, 2012 1:03 PM
  • Thank you Chuck, I've put your info in web.config and modified target framework to 4.0 and all seems to work.

    Thank you again for your help.

    Best regards

    Fabrizio

    Wednesday, May 30, 2012 1:53 PM
  • Thanks VERY much Chuck! This was a real head-scratcher until I saw your post!
    Friday, June 17, 2016 4:32 PM
  • Me ha sido de mucha ayuda se me presento el mismo error muchas gracias.
    Friday, April 14, 2017 4:39 AM