0

I am creating a Winform for a user to run an SSIS package. The following is a solution I have found:

    private void button1_Click(object sender, EventArgs e)
    {
        string sPackage = @"C:\FilePath.dtsx";
        string sConfig = @"C:\FilePath.xml";

        OpenFileDialog fDialog = new OpenFileDialog();
        fDialog.Title = "Open Package";
        fDialog.Filter = "SSIS Package (*.dts, *.dtsx)|*.dts;*.dtsx";
        fDialog.InitialDirectory = @"C:\";
        sPackage = fDialog.FileName.ToString();

        OpenFileDialog f2Dialog = new OpenFileDialog();
        fDialog.Title = "Open Package";
        fDialog.Filter = "SSIS Package (*.dts, *.dtsx)|*.dts;*.dtsx";
        fDialog.InitialDirectory = @"C:\";
        sConfig = fDialog.FileName.ToString();

        MyEventListener eventListener = new MyEventListener();    
        Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
        Microsoft.SqlServer.Dts.Runtime.Package pkg = app.LoadPackage(sPackage, eventListener, false);

        Microsoft.SqlServer.Dts.Runtime.DTSExecResult pkgResults = pkg.Execute(null, null, eventListener , null, null);
        MessageBox.Show(pkgResults.ToString());



    }

    class MyEventListener : DefaultEvents
    {
        public override bool OnError(DtsObject source, int errorCode, string subComponent,
          string description, string helpFile, int helpContext, string idofInterfaceWithError)
        {
            // Add application-specific diagnostics here.
            MessageBox.Show("Error in " + "/t" + source + "/t" + subComponent + "/t" + description);
            return false;
        }
    }

The following is the line of code in which I am getting this error:

Microsoft.SqlServer.Dts.Runtime.Package pkg = app.LoadPackage(sPackage, eventListener, false);

I have the correct file path for the .dtxs package. I have experience in SSIS just not trying to execute from a Winform in C#. What am I doing wrong?

J.S. Orris
  • 4,653
  • 12
  • 49
  • 89
  • What is the error message you are receiving? If you made it `app.LoadPackage(sPackage, null);` does it work? – billinkc Mar 23 '15 at 19:24
  • It does not work still I make it `(sPackage, null)`. The following is the full error: `Error in /t Microsoft.SlServer.Dts.Runtime.Packge /t/t Unable to load the package as XML because of package does not have a valid XML format. Aspecific XML parser error will be posted.` – J.S. Orris Mar 23 '15 at 19:38
  • Then I get another error: `Error in Microsoft.SqlServer.Dts.Runtime.Package /t/t Failed to open package file due to error 0x80070057 The parameter is incorrect. This occurs when loading a package and the file cannot be opened or loaded correctly into the XML document. This can be the result of specifying an incorrect file name when calling LoadPackage or the specified XML file has an incorrect format` – J.S. Orris Mar 23 '15 at 19:40
  • Have you inspected the value for sPackage? I suspect it is not what the LoadPackage method is expecting – billinkc Mar 23 '15 at 19:42
  • I have debugged. It is the FilePath for the .dtsx package. Is it a permission thing maybe? – J.S. Orris Mar 23 '15 at 19:48
  • Smells more like you are passing an invalid path to the package or you have the wrong version of the SSIS assemblies referenced or maybe you've got something weird like password protected packages – billinkc Mar 23 '15 at 20:00
  • @billinkc sorry for delay in response...had to run an errand. Am I correct in putting the path to the .dtsx file? I have a project [integration services project] and Im trying to run a single package from that project. I have inserted the string path for the package...do I need to do it for the project as well? – J.S. Orris Mar 23 '15 at 22:37

1 Answers1

0

Found answer here here. Answered by @Faiz.

    private void button1_Click(object sender, EventArgs e)
    {
        string pkgLocation;
        Package pkg;
        Microsoft.SqlServer.Dts.Runtime.Application app;
        DTSExecResult pkgResults;

        MyEventListener eventListener = new MyEventListener();

        pkgLocation =
          @"C:\FilePath.dtsx";

        app = new Microsoft.SqlServer.Dts.Runtime.Application();
        pkg = app.LoadPackage(pkgLocation, eventListener);
        pkgResults = pkg.Execute(null, null, eventListener, null, null);

        MessageBox.Show(pkgResults.ToString());

    }

    class MyEventListener : DefaultEvents
    {
        public override bool OnError(DtsObject source, int errorCode, string subComponent,
          string description, string helpFile, int helpContext, string idofInterfaceWithError)
        {
            // Add application-specific diagnostics here.
            MessageBox.Show("Error in " + "/t" + source + "/t" + subComponent + "/t" + description);
            return false;
        }
    }
Community
  • 1
  • 1
J.S. Orris
  • 4,653
  • 12
  • 49
  • 89
  • Accounting for your change in variable names, the only difference appears to be the omission of `sPackage = fDialog.FileName.ToString()`. Does that seem accurate to you? – billinkc Mar 24 '15 at 00:38
  • @billinkc it works..I just have to get the assembly for my version – J.S. Orris Mar 24 '15 at 00:45
  • Right, it works but aren't you curious *why* it works compared to the original code? – billinkc Mar 24 '15 at 00:48
  • I debugged and stepped through original code. The following is what was screwing me up: `sPackage = fDialog.FileName.ToString();` and `sConfig = fDialog.FileName.ToString()` when looking at the autos...the filepaths were now null and therefore was giving a bad parameter...but yes, I am curious as to what the other code did in the original block that was eliminated in the new block. May you explain? – J.S. Orris Mar 24 '15 at 00:55