How to capture SSIS event handlers programmatically in C#(2005) ? -
03-28-2006
, 04:02 AM
I have a package.dtsx. I want to run it from a windows application.
Iam using a button control to run this package. I would like to show progress
i.e. percent completed in a progress bar. How can I do it ?
I have inherited the class "DefaultEvents" to override eventhandlers.
If I execute the below code, "OnProgress" event is getting fired only once
at the Percentage Complete is 0.
I would like to know how much percentage of package execution is completed
(till the completion of package execution) so that I can show the same in a
progress bar.
Can any one help me ?
The code is mentioned below.
WindowsForm1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.SqlServer.Dts.Runtime;
namespace Electrabel_WindowsApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string Location;
Package pkg;
Microsoft.SqlServer.Dts.Runtime.Application app;
DTSExecResult pkgResults;
Location = @"C:\Bhanu\Project\Test Integration Services
Project\Test Integration Services Project\Package.dtsx";
app = new Microsoft.SqlServer.Dts.Runtime.Application();
pkg = app.LoadPackage(Location, null);
progressBar1.Minimum = 0;
progressBar1.Maximum = 100;
MyEventsClass MEC = new MyEventsClass();
// progressBar1.Increment(10);
pkg.Validate(null, null, MEC, null);
// progressBar1.Increment(40);
//pkgResults = pkg.Execute();
Executable E = pkg.Executables[0];
TaskHost TH = E as TaskHost;
TH.Validate(null, null, MEC, null);
pkgResults= TH.Execute(null, null, MEC, null, null);
// progressBar1.Increment(50);
MessageBox.Show(pkgResults.ToString());
}
}
}
Class1.cs
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
namespace Electrabel_WindowsApp
{
class MyEventsClass : DefaultEvents
{
public override void OnPreValidate(Executable exec, ref bool
fireAgain)
{
MessageBox.Show("OnPreValidate");
}
public override void OnPostValidate(Executable exec, ref bool
fireAgain)
{
MessageBox.Show("OnPostValidate");
}
public override void OnPreExecute(Executable exec, ref bool fireAgain)
{
MessageBox.Show("OnPreExecute");
}
public override void OnPostExecute(Executable exec, ref bool
fireAgain)
{
MessageBox.Show("OnPostExecute");
}
public override void OnProgress(TaskHost taskHost, string
progressDescription, int percentComplete, int progressCountLow, int
progressCountHigh, string subComponent, ref bool fireAgain)
{
MessageBox.Show("OnProgress" + percentComplete.ToString() +
progressDescription + taskHost.Description );
}
public override void OnExecutionStatusChanged(Executable exec,
DTSExecStatus newStatus, ref bool fireAgain)
{
MessageBox.Show("OnExecutionStatusChanged " +
newStatus.ToString() );
}
}
} |