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.
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
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());
Press F5 after completing the code and click on the button, the code will execute the package and return the success message.
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’
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.
2 Comments (+add yours?)