How to Execute SSIS Package part#3

Previous Posts:

How to Execute SSIS package part#1

How to Execute SSIS Package part#2

Using C# code to execute Package:

Open Visual Studio and select Window Application, add reference to Microsoft.SQLServer.ManagedDTD.dll file. To execute SSIS package from C# code we need above file.

image

If you didn’t find in the .NET tab browse the file by using the following path C:\Program Files(x86)\Microsoft SQL Server\100\SDK\Assemblies

image

Now Add a button in the Form and double click on the button to add the execution code. Add the Runtime class using ‘using’ keword

using Microsoft.SqlServer.Dts.Runtime

Execution Code:

String path = @" D:\PackagePath\Package.dtsx";
Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
Package pack = app.LoadPackage(path, null);
pack.Variables["UserID"].Value = "Test";
DTSExecResult Result = pack.Execute();
MessageBox.Show(Result.ToString());

image

Press F5 after completing the code and click on the button, the code will execute the package and return the success message.

image

Using Batch File:

Write the following code in a notepad and save it as .bat file, the code contains the same command which we used in ‘Command Prompt’ and ‘PowerShell’

image

1. We can use this batch file and add as a button to BIDS to execute SSIS package(go through how add a button to BIDS )

2. Task Scheduler/SQL Agent can schedules batch.

About these ads

2 Comments (+add yours?)

  1. Trackback: How to execute SSIS package part#4 « msbimentalist
  2. Trackback: Link Resource # 25: Sept 12–Sept 24 « Dactylonomy of Web Resource

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.

Join 410 other followers

%d bloggers like this: