Click here to Skip to main content
13,355,311 members (59,807 online)
Click here to Skip to main content
Add your own
alternative version


82 bookmarked
Posted 25 May 2006

Execute SQL Server 2005 Integration Services package from C#

, 25 May 2006
Rate this:
Please Sign up or sign in to vote.
Learn how to load and execute a SQL Server 2005 Integration Services package from C# code


There are many ways to execute a SQL Server 2005 Integration Services (SSIS) package.  You can use the command line utility DTExec.exe or its window equivalent, DTExecUI.exe. A package can be executed within SQL Server Business Intelligence Studio (Visual Studio) or from a SQL Server Agent Job Step. A package can also be executed from .NET code!

Example SSIS Package

For the purposes of demonstration, I created a simple package that takes some data out of a SQL Server AdventureWorks database and dumps it into a flatfile. The package also has one variable.

Sample screenshot

Sample screenshot

In any kind of "real world" scenario, your package will usually be driven by a configuration file.  An SSIS configuration file is an XML file with a .dtsConfig extension that contains settings you can apply to a package (without actually changing or editing the package). In my example files, you can edit the configuration file with your SQL Server and flat file connection information and run the package. You'll never have to edit the actual package file. Here's a very good tutorial on configuration file syntax. Configurations can also be stored in a SQL Server table, but I won't cover that here.

Let's Start Coding...

You need to add a reference to Microsoft.SQLServer.ManagedDTS.dll. I believe that this DLL is only installed on a machine that has SQL Server components installed. 

Sample screenshot

The amount of code to execute a SSIS package is surprisingly small and concise. Notice that I added a using directive for the Microsoft.SqlServer.Dts.Runtime namespace.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;

namespace ExecuteSSIS
  class Program
    static void Main(string[] args)
        Application app = new Application();
        // Load package from file system
        Package package = app.LoadPackage("c:\\ExamplePackage.dtsx", null);
        Variables vars = package.Variables;
        vars["MyVariable"].Value = "value from c#";

        DTSExecResult result = package.Execute();

        Console.WriteLine("Package Execution results: {0}",result.ToString());

        // Load package from SQL Server
        Package package2 = app.LoadFromSqlServer(
            "ExamplePackage","server_name", "sa", "your_password", null);

        Variables vars2 = package2.Variables;
        vars2["MyVariable"].Value = "value from c# again";

        DTSExecResult result2 = package2.Execute();

        Console.WriteLine("Package Execution results: {0}", 

First, you create an Application object, which provides access to the DTS (Integration Services) runtime.  Then you use the Application object to load a package from either the file system or from SQL Server, I've demonstrated both. Once you have the package loaded into a Package object, you call the ImportConfigurationFile() method to load and apply the configuration file to the package. The Package object also has a Variables collection that provides access to the package's variable. Finally, to actually execute a package, call the Execute() method.


This article was meant to quickly demonstrate how to load and execute a package. There is much, much more you can do with the managed DTS namespace. There are objects and additional namespaces that allow you to load and inspect packages or even create new packages from .NET code.


  • 25th May, 2006: Initial post


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Jeff Modzel
Web Developer
United States United States
Technical Architect
Sungard HE

You may also be interested in...


Comments and Discussions

GeneralRe: What about calling a package from ASP.NET Pin
ABlokha7718-May-07 2:56
memberABlokha7718-May-07 2:56 
GeneralOutstanding! Pin
Wbehning6-Nov-06 13:44
memberWbehning6-Nov-06 13:44 
GeneralThanks. Pin
Slackshot16-Oct-06 6:54
memberSlackshot16-Oct-06 6:54 
GeneralThanks Pin
Fergal Boden7-Sep-06 1:07
memberFergal Boden7-Sep-06 1:07 
General[OLE DB Destination [306]] Error: The AcquireConnection method call to the connection manager failed with error code 0xC0202009. Pin
Balayc29-Jul-06 2:11
memberBalayc29-Jul-06 2:11 
GeneralWrong references Pin
vavigli20-Jul-06 11:38
membervavigli20-Jul-06 11:38 
QuestionRun Time Error While Execute SSIS Package from C#(Windows Application) Pin
deepumi5-Jun-06 16:31
memberdeepumi5-Jun-06 16:31 
AnswerRe: Run Time Error While Execute SSIS Package from C#(Windows Application) Pin
Jeff Modzel6-Jun-06 4:58
memberJeff Modzel6-Jun-06 4:58 
The problem is that Application exists as a valid class in multiple namespaces. You can do one of two things.

1) Explicitly define the class like:

Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();

or 2) Create a namespace alias like:

using DTS = Microsoft.SqlServer.Dts.Runtime;


DTS.Application app = new DTS.Application();
GeneralPassing global variables back to C# from SSIS Pin
Nigel-Findlater30-May-06 21:53
memberNigel-Findlater30-May-06 21:53 
GeneralRe: Passing global variables back to C# from SSIS Pin
Jeff Modzel31-May-06 3:43
memberJeff Modzel31-May-06 3:43 
AnswerRe: Passing global variables back to C# from SSIS Pin
Jeff Modzel1-Jun-06 8:44
memberJeff Modzel1-Jun-06 8:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 25 May 2006
Article Copyright 2006 by Jeff Modzel
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid