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);
}
}
}