This article explains how to execute an SSIS package task of a package that is stored in a file system.
- Microsoft Visual Studio 2008 (or later editions)
- SQL Server 2005 (or later editions)
- AdventureWorks2008R2 database (downloadable database file available here)
If the above requirements are all met, we will begin by launching Microsoft Visual Studio edition.
Create a new project Integration Services Project which is located under Business Intelligence Projects.
After you have named the new project, proceed to click and drag the script task in Control Flow pane of the new package.
Right click the script task and click on “Edit”
Under the Script Task Editor change the “ScriptLanguage” to “Microsoft Visual C# 2008”.
In Project Explorer import relevant references and ensure that you have declared namespaces as below:
using RuntimeWrapper = Microsoft.SqlServer.Dts.Runtime.Wrapper;
After declarations, create an instance of application and package:
Application SIFISO_app = new Application();
Package p = new Package();
Insert file sytem connection:
ConnectionManager cm_DES = p.Connections.Add(“FILE”);
cm_DES.Name = “local_pkg”;
cm_DES.ConnectionString = string.Format(“C:\\TEMP\\pkg_Execute_Sql_Tasks_ROWCOUNT.dtsx”);
Insert an Execute Package Task onto a package and set component propeties:
Executable exec = p.Executables.Add(“STOCK:ExecutePackageTask”);
TaskHost th = exec as TaskHost;
th.Properties[“Name”].SetValue(th, “Execute selectSIFISO Package”);
th.Properties[“Description”].SetValue(th, “Execute selectSIFISO Package”);
We then save the package into a file system.
Dts.TaskResult = (int)ScriptResults.Success;
SIFISO_app.SaveToXml(“C:\\TEMP\\pkg_Exec_Pkg_Tasks.dtsx”, dyna_pkg, null);
It’s that simple!
You can now execute your script task and the package will be created in location you specified.