Thursday, 9 October 2008

Run a DTS package through an application

To run a dts package through code:

Using:
using System.Threading;
using DTS;

Declare:
private Thread dts;

Method:
private void CallDTS()
{
dts = new Thread(new ThreadStart(RunDTSPackage));
dts.Start
}

private void RunDTSPackage()
{
try
{
object obj = new object();

PackageClass csDTS = new PackageClass();
csDTS.LoadFromSQLServer("Server", null, null, DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection, null, null, null, "PackageName", ref obj);
csDTS.Execute();
csDTS.UnInitialize();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

You might need to wait until the package is finished running before you carry on and call other methods so check for:
while (dts.IsAlive)
{
}
DoSomething();

Thats it.

No comments:

Free Hit Counter