02
Aug
07

Running .dtsx from C#

I figure out this code when I try to run the .dtsx package from C#.
Quite a prospect, I guess. The .dtsx package (Sql Server Integration Service) itself has open many possibilites to do some ETL and Data Warehousing. I won’t cover the ETL Tutorial with SSIS in this post though, I’m still learning on it.

I just want to share the code I made to run simple .dtsx package. When I try searching the tutorial in http://msdn2.microsoft.com/en-us/library/ms136090.aspx I got some errors when I compiled it, therefore I made some slight changes to make it work:

Here is my code:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
namespace MyConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            string pkgLocation;
            
           
            Package pkg;
            Application app;
            DTSExecResult pkgResults;

            pkgLocation =
            @”C:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\TheIntegration\TheIntegration\Package.dtsx”;
            app = new Application();
            pkg = (Package)app.LoadPackage(pkgLocation, true, null);
            pkgResults = pkg.Execute();

            Console.WriteLine(pkgResults.ToString());
            Console.ReadKey();
        

          
        }
    }

}

Please note that the location string is the location of your .dtsx file. One more thing, don’t forget to add Microsoft.SQLServer.DTSRuntimeWrap.dll as reference.

Hope it help!


3 Responses to “Running .dtsx from C#”


  1. February 13, 2008 at 11:57 am

    The code is compiling fine.. but when i execute the code i get the error DTUSR_FAILER.. and the data doest get transfered into SQL.
    However when i run the dtsx package from its location by using the execute option it works..
    Awaitin an early reply..

    Regards
    Mustafa Kachwalla

  2. June 30, 2008 at 12:45 pm

    Open the package, goto it’s Data Flow property and check the ProtectionLevel property in the properties. Try using DontSaveSensitive, this might work, if not try using other options in the ProtectionLevel property.

    Zain.

  3. August 7, 2008 at 3:39 am

    And what about variables and parameters? :S


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.