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?