Welcome to MSDN Blogs Sign in | Join | Help

Syndication

Tags

    No tags have been created or used yet.
Executing a SQL Server 2008 SSIS Package

Sometimes I just want to run a SSIS package without creating a job in SQL Server job. 

Dangerous??  Well not really just sometimes, especially in production, unwise.

Nonetheless here is my raw example for sharing with others.  Make sure you add the reference to Microsoft.SQLServer.ManagedDTS for DTS.Runtime.

using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.SqlServer.Dts.Runtime;

namespace LaunchSSISPackageAgent
{
    class Program
    {
        static void Main(string[] args)
        {
            int returnCode;

            //returnCode = RunSSISPackage( "myServer", ".", "mypackage" );

        }


         // Always mention sources of ideas...

// http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.dts.runtime.application.existsonsqlserver(SQL.90).aspx
        public static int RunSSISPackage (string packageServer, string packagePath, string packageName)
        {
            Package myPackage;
            Application integrationServices = new Application();
            Int32  ExecuteCode = 0;

            // Combine path and file name.

                // Package is stored in MSDB.
                // Combine logical path and package name.
            // Verify that the package was saved.
            //Boolean packageExists = app.ExistsOnSqlServer(packageName, packageServer, null, null);
            //Console.WriteLine("Package exists? {0}", packageExists);

                if (integrationServices.ExistsOnSqlServer(packageName, packageServer, null, null))
                {
                    myPackage = integrationServices.LoadFromSqlServer(packageName, packageServer, null, null, null);
                    DateTime pkgCreation = myPackage.CreationDate;
                    Console.WriteLine("Creation Date = {0}", pkgCreation);
                    ExecuteCode = (Int32) myPackage.Execute();
                    Console.WriteLine("Package Executed.. ");
                    Console.WriteLine(ExecuteCode);
                    Console.Read();
                    return ExecuteCode;

                }
                else
                {
                   throw new ApplicationException("Invalid package name or location: " + packagePath);
                }

            }

}

Published Tuesday, February 10, 2009 7:35 PM by SylviaV

Comments

# Executing a SQL Server 2008 SSIS Package - Click & Solve @ Tuesday, February 10, 2009 10:39 PM

PingBack from http://www.clickandsolve.com/?p=6153

Executing a SQL Server 2008 SSIS Package - Click & Solve

Anonymous comments are disabled
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement  
Page view tracker