Home > Archive > MS SQL Server DTS > March 2006 > How to capture SSIS event handlers programmatically in C#(2005) ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to capture SSIS event handlers programmatically in C#(2005) ?
Bhanu

2006-03-28, 3:28 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_WindowsAp
p
{
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\Tes
t 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_WindowsAp
p
{
class MyEventsClass : DefaultEvents
{

public override void OnPreValidate(Execut
able exec, ref bool
fireAgain)
{
MessageBox.Show("OnPreValidate");

}

public override void OnPostValidate(Execu
table exec, ref bool
fireAgain)
{
MessageBox.Show("OnPostValidate");

}

public override void OnPreExecute(Executa
ble exec, ref bool fireAgain)
{
MessageBox.Show("OnPreExecute");
}

public override void OnPostExecute(Execut
able 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 OnExecutionStatusCha
nged(Executable exec,
DTSExecStatus newStatus, ref bool fireAgain)
{
MessageBox.Show(" OnExecutionStatusCha
nged " +
newStatus.ToString() );

}
}
}



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com