Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

SSIS Package Not Executing from C#

$
0
0

Hi all!  Trying to get a local SSIS package to kick off after the user clicks the Audit button on a Windows form project I built.  Here is the code so far:

            //Variable & object declaration
            string pkgLocation;
            SSIS.Package pkg;
            SSIS.Application app;
            SSIS.DTSExecResult pkgResults;

            //Create new ofd
            OpenFileDialog ofd = new OpenFileDialog();

            //Set ofd settings
            ofd.Title = "Select audit file for processing";
            ofd.Filter = "*.txt files|*.txt";
            ofd.FilterIndex = 2;

            //Display ofd
            DialogResult result = ofd.ShowDialog();

            //Set path for package to execute
            pkgLocation =
                @"C:\Documents\Test\ImportFile.dtsx";
            app = new SSIS.Application();
            pkg = app.LoadPackage(pkgLocation, null);

            //Send variables to package
            pkg.Variables["User::InputFile"].Value = ofd.FileName;

            MessageBox.Show("Next command is to execute package using variable: " + pkg.Variables["User::InputFile"].Value);

            //Execute package
            pkgResults = pkg.Execute();

            MessageBox.Show("Execute command sent");

            //Check the results for Failure and Success
            if (pkgResults == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure)
            {
                string err = "";
                foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in pkg.Errors)
                {
                    string error = local_DtsError.Description.ToString();
                    err = err + error;
                }
            }
            if (pkgResults == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success)
            {
                MessageBox.Show("SSIS import triggered successfully.");
            }
            //You can also return the error or Execution Result
            //return Error;

Here are the details:

MessageBox.Show("Next command is to execute package using variable: " + pkg.Variables["User::InputFile"].Value);

and

MessageBox.Show("Execute command sent");

both appear as expected, but then the project just hangs (it seems).  I have the SSIS project open in Visual Studio as well while debugging, and when it gets to that point in the script, VS does not appear to be running the SSIS.  Also, I have never seen the messagebox from this line:

MessageBox.Show("SSIS import triggered successfully.");

so it seems it's hanging somewhere between sending pkg.Execute() and actually starting the SSIS project.

Any thoughts?


Viewing all articles
Browse latest Browse all 24688

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>