{"id":9500,"date":"2021-12-31T15:00:01","date_gmt":"2021-12-31T15:00:01","guid":{"rendered":"https:\/\/zappysys.com\/blog\/?p=9500"},"modified":"2025-12-11T11:23:03","modified_gmt":"2025-12-11T11:23:03","slug":"create-ssis-package-programmatically-add-execute-connections-tasks","status":"publish","type":"post","link":"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/","title":{"rendered":"How to create SSIS Package Programmatically (Add \/ Execute Tasks)"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>In this post, we will see how to create SSIS Package Programmatically to use <a href=\"https:\/\/zappysys.com\/products\/ssis-powerpack\/\" target=\"_blank\" rel=\"noopener\">ZappySys SSIS PowerPack<\/a>. This blog post assumes you have basic knowledge of Programming language like C# and you have installed <strong>Visual Studio Express<\/strong> or a similar product (<strong>VS Code not supported<\/strong>).<\/p>\n<div class=\"content_block\" id=\"custom_post_widget-2523\"><h2><span id=\"Prerequisites\">Prerequisites<\/span><\/h2>\r\nBefore we perform the steps listed in this article, you will need to make sure the following prerequisites are met:\r\n<ol style=\"margin-left: 1.5em;\">\r\n \t<li><abbr title=\"SQL Server Integration Services\">SSIS<\/abbr> designer installed.\u00a0Sometimes it is referred to as <abbr title=\"Business Intelligence Development Studio\">BIDS<\/abbr> or <abbr title=\"SQL Server Data Tools\">SSDT<\/abbr> (<a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/ssdt\/download-sql-server-data-tools-ssdt\" target=\"_blank\" rel=\"noopener\">download it from the Microsoft site<\/a>).<\/li>\r\n \t<li>Basic knowledge of SSIS package\u00a0development using\u00a0<em>Microsoft SQL Server Integration Services<\/em>.<\/li>\r\n \t<li>Make sure\u00a0<span style=\"text-decoration: underline;\"><a href=\"https:\/\/zappysys.com\/products\/ssis-powerpack\/\" target=\"_blank\" rel=\"noopener\">ZappySys SSIS PowerPack<\/a><\/span>\u00a0is installed (<a href=\"https:\/\/zappysys.com\/products\/ssis-powerpack\/download\/\" target=\"_blank\" rel=\"noopener\">download it<\/a>, if you haven't already).<\/li>\r\n \t<li>(<em>Optional step<\/em>)<em>.<\/em>\u00a0<a href=\"https:\/\/zappysys.zendesk.com\/hc\/en-us\/articles\/360035974593\" target=\"_blank\" rel=\"noopener\">Read this article<\/a>, if you are planning to deploy packages to a server and schedule their execution later.<\/li>\r\n<\/ol><\/div>\n<h2>Add SSIS Dll References<\/h2>\n<p>The very first thing is to create a C# Project (i.e. Console or WinForm). Add SSIS dll reference.<\/p>\n<p><a href=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9503\" src=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio.png\" alt=\"\" width=\"778\" height=\"604\" srcset=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio.png 778w, https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio-300x233.png 300w, https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio-768x596.png 768w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><\/a><\/p>\n<p>You will need the following references in your project. The below example is for SSIS 2017 (Version 14.x.x)<\/p>\n<ul>\n<li>For SSIS 2012 change to Version=11.0.0.0<\/li>\n<li>For SSIS 2014 change to Version=12.0.0.0<\/li>\n<li>For SSIS 2016 change to Version=13.0.0.0<\/li>\n<li>For SSIS 2017 change to Version=14.0.0.0<\/li>\n<li>For SSIS 2019 change to Version=15.0.0.0<\/li>\n<li>And may be future versions same way &#8230;.<\/li>\n<\/ul>\n<pre class=\"lang:xhtml decode:true\">&lt;Reference Include=\"Microsoft.SqlServer.Dts.Design\"\/&gt;\r\n&lt;Reference Include=\"Microsoft.SqlServer.DTSPipelineWrap\" \/&gt;\r\n&lt;Reference Include=\"Microsoft.SQLServer.DTSRuntimeWrap\" \/&gt;\r\n&lt;Reference Include=\"Microsoft.SQLServer.ManagedDTS\" \/&gt;\r\n&lt;Reference Include=\"Microsoft.SqlServer.PipelineHost\" \/&gt;\r\n<\/pre>\n<h2>Step-By-Step Example (Create SSIS Package Programmatically &#8211; C#)<\/h2>\n<p>Now let&#8217;s see each piece to create SSIS Package in code and later we will show the full code.<\/p>\n<h3>Import Namespaces<\/h3>\n<p>First step is at the top you need to import some namespaces.<\/p>\n<pre class=\"\">using Microsoft.SqlServer.Dts.Runtime;\r\nusing Microsoft.SqlServer.Dts.Pipeline;\r\n\/\/using Microsoft.SqlServer.Dts.Pipeline.Wrapper;\r\n\/\/using Microsoft.SqlServer.Dts.Runtime.Wrapper;<\/pre>\n<h3><\/h3>\n<h3>Create SSIS Package<\/h3>\n<p>Here how you can create SSIS Package instance in code<\/p>\n<pre class=\"\"> var p = new Package();<\/pre>\n<h3>Add SSIS Connection<\/h3>\n<p>Now lets add connection manager to our package instance. To add connection you will need two pieces. Creation Name (i.e. ZS-SFTP) and ConnectionString. You can find creation name from exsing Dtsx file by opening in text editor.<\/p>\n<pre class=\"\">var conn1=p.Connections.Add(\"ZS-SFTP\");\r\nconn1.Name = \"MySftpConnection\";\r\nconn1.ConnectionString= \"Protocol=Sftp;ServerName=127.0.0.1;Port=0;LogonType=Normal;UserName=zstest;Password=zstest123\";<\/pre>\n<h4>How to find CreationName of SSIS Connection manager<\/h4>\n<p>To find the creation name of your Connection Type open an existing DTSX file where you had similar connection type in the package. Locate node like below and check CrewationName. It can be a friendly name or can be fully qualified assembly name. Both ways is fine but a friendly name is easy to remember.<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;DTS:ConnectionManagers&gt;\r\n  &lt;DTS:ConnectionManager\r\n    DTS:refId=\"Package.ConnectionManagers[RedshiftConn1]\"\r\n    DTS:CreationName=\"ZS-POSTGRESQL\"\r\n    .........\r\n    .........<\/pre>\n<h4>How to find ConnectionString<\/h4>\n<p>Now another thing you need to know is the exact connectionstring. You can go to SSIS Designer and right-click on Connection Icon and check Properties Grid. It will show you ConnectionString or you can use the above technique &gt; Open DTSX file in notepad and find connectinstring there.<\/p>\n<p>ConnectionString doesnt include any passwords \/ secrets. So manually append those properties in your connectionstring when you set in code.<\/p>\n<h3>Add SSIS Task<\/h3>\n<p>Now let&#8217;s add task in our SSIS Package instance. To create SSIS Task programmatically in code, you need to know the exact type name (i.e. creation name). As we discussed earlier check your dtsx file to know the creation name for the task you like to create. In the below code we used a friendly name which is not supported in SSIS 2012 so for that you must use full name. For SSIS 2014 or higher you can use friendly names.<\/p>\n<p>You can also find it in file like this (example of SSIS 2017 and 2019 folders)<br \/>\nC:\\Program Files (x86)\\Microsoft SQL Server\\140\\DTS\\UpgradeMappings\\ZappySys.PowerPack140.Extensions.xml<br \/>\nC:\\Program Files (x86)\\Microsoft SQL Server\\150\\DTS\\UpgradeMappings\\ZappySys.PowerPack150.Extensions.xml<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:c# decode:true\">\/\/var SSIS_VERSION = \"110\"; \/\/110=SQL2012, 120=SQL2014, 130=SQL2016, 140=SQL2017, 150=SQL2019\r\n\/\/For SSIS 2012\r\nvar SFTP_TASK_2012 = \"ZappySys.PowerPack.Task.SecureFtpTask.SecureFtpTask, ZappySys.PowerPack110, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1903265a93eae502\";\r\n\/\/For SSIS 2014 or higher\r\n\/\/Goto folder like this and find zappysys extension file \r\n\/\/(e.g. 140) =&gt; C:\\Program Files (x86)\\Microsoft SQL Server\\140\\DTS\\UpgradeMappings\\ZappySys.PowerPack140.Extensions.xml\r\n\/\/Find Task creation name there\r\nvar SFTP_TASK = \"ZappySys.SecureFtpTask\";\r\n\r\nvar tsk1 = p.Executables.Add(SFTP_TASK) as TaskHost;\r\ntsk1.Properties[\"SourceStorageConnection\"].SetValue(tsk1, \"MySftpConnection\");\r\ntsk1.Properties[\"StorageAction\"].SetValue(tsk1, 10); \/\/DownloadFileFromFtp [10] find numeric value for this enum from help file&gt; properties https:\/\/zappysys.com\/onlinehelp\/ssis-powerpack\/scr\/ssis-sftp-ftp-ftps-task.htm\r\ntsk1.Properties[\"SourcePathValue\"].SetValue(tsk1, \"subfolder\/localsubfile1.csv\");\r\ntsk1.Properties[\"TargetPathValue\"].SetValue(tsk1, @\"c:\\temp\\\");\r\ntsk1.Properties[\"FileOverwriteAction\"].SetValue(tsk1, 2); \/\/OverwriteAll [2]\r\n<\/pre>\n<h3>Execute SSIS Package<\/h3>\n<p>Now let&#8217;s execute the package using the below line<\/p>\n<pre class=\"\"> var status =p.Execute();<\/pre>\n<h3>Check Execution Errors<\/h3>\n<p>At the end you need to check execution errors if any.<\/p>\n<pre class=\"lang:c# decode:true\">if (status != DTSExecResult.Success)\r\n{\r\n\tstring errs = p.Errors.Cast&lt;DtsError&gt;().Aggregate(\"\",\r\n           (current, err) =&gt; current + string.Format(\"Source={0}, Err={1}\", err.Source, err.Description));\r\n\tthrow new Exception(\"Package status was &gt;&gt; \" + status + \" &gt;&gt; \" + errs);\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h3>Full Code<\/h3>\n<p>Here is the full code<\/p>\n<pre class=\"lang:c# decode:true\">using System;\r\nusing System.Linq;\r\nusing System.Runtime.InteropServices;\r\nusing Microsoft.SqlServer.Dts.Pipeline.Wrapper;\r\nusing Microsoft.SqlServer.Dts.Runtime;\r\n\/*\r\nFor SSIS 2012 - Compile with .net 4.0\r\nFor SSIS 2014-2017 - Compile with .net 4.5 \r\nFor SSIS 2019 - Compile with .net 4.6.2\r\n *\/\r\n\r\n\/\/current one is SSIS 2017 (140 dlls)\r\n\/*\r\n * References needed for SSIS 2017 , for 2019 change 14.0.0.0 to 15.0.0.0\r\n * \r\n    &lt;Reference Include=\"Microsoft.SqlServer.DtsMsg, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL\" \/&gt;\r\n    &lt;Reference Include=\"Microsoft.SqlServer.Dts.Design, Version=14.0.0.0, PublicKeyToken=89845dcd8080cc91\" \/&gt;\r\n    &lt;Reference Include=\"Microsoft.SqlServer.DTSPipelineWrap, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL\" \/&gt;\r\n    &lt;Reference Include=\"Microsoft.SQLServer.DTSRuntimeWrap, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91\" \/&gt;\r\n    &lt;Reference Include=\"Microsoft.SQLServer.ManagedDTS, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL\" \/&gt;\r\n    &lt;Reference Include=\"Microsoft.SqlServer.PipelineHost, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL\" \/&gt; \r\n *\/\r\nnamespace SSISCodeDemo\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            \r\n            \/\/Create_SSIS_Controlflow_Task_Demo();\r\n            Create_SSIS_Dataflow_Source_Component_Demo();\r\n\r\n            \/\/Create_SSIS_Connection_Demo();\r\n            \/\/Create_SSIS_Variable_Demo();\r\n            \/\/Create_SSIS_Connect_Tasks_Demo();\r\n\r\n        }\r\n\r\n        private static void Create_SSIS_Controlflow_Task_Demo()\r\n        {\r\n            var p = new Microsoft.SqlServer.Dts.Runtime.Package();\r\n\r\n            var conn1 = p.Connections.Add(\"ZS-SFTP\");\r\n            conn1.Name = \"MySftpConnection\";\r\n            conn1.ConnectionString = \"Protocol=Sftp;ServerName=127.0.0.1;Port=0;LogonType=Normal;UserName=zstest;Password=zstest123\";\r\n\r\n            \/\/var SSIS_VERSION = \"110\"; \/\/110=SQL2012, 120=SQL2014, 130=SQL2016, 140=SQL2017, 150=SQL2019\r\n            \/\/For SSIS 2012\r\n            var SFTP_TASK_2012 = \"ZappySys.PowerPack.Task.SecureFtpTask.SecureFtpTask, ZappySys.PowerPack110, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1903265a93eae502\";\r\n            \/\/For SSIS 2014 or higher\r\n            \/\/Goto folder like this and find zappysys extension file (e.g. 140) =&gt; C:\\Program Files (x86)\\Microsoft SQL Server\\140\\DTS\\UpgradeMappings\\ZappySys.PowerPack140.Extensions.xml\r\n            \/\/Find Task creation name there\r\n            var SFTP_TASK = \"ZappySys.SecureFtpTask\";\r\n\r\n            var tsk1 = p.Executables.Add(SFTP_TASK) as TaskHost;\r\n            tsk1.Name = \"SFTP_Task1\";\r\n            tsk1.Properties[\"SourceStorageConnection\"].SetValue(tsk1, \"MySftpConnection\");\r\n            tsk1.Properties[\"StorageAction\"].SetValue(tsk1, 10); \/\/DownloadFileFromFtp [10] find numeric value for this enum from help file&gt; properties https:\/\/zappysys.com\/onlinehelp\/ssis-powerpack\/scr\/ssis-sftp-ftp-ftps-task.htm\r\n            tsk1.Properties[\"SourcePathValue\"].SetValue(tsk1, \"subfolder\/localsubfile1.csv\");\r\n            tsk1.Properties[\"TargetPathValue\"].SetValue(tsk1, @\"c:\\temp\\\");\r\n            tsk1.Properties[\"FileOverwriteAction\"].SetValue(tsk1, 2); \/\/OverwriteAll [2]\r\n\r\n\r\n            \/*\r\n             Go to package file (*.dtsx) &gt; Open in Notepad &gt; and findout which properties set. Do same way (ignore some default proprties)\r\n             Some enum properties needs numeric values &gt; Check Task \/ Component help file to findout number for that\r\n\r\n      &lt;DTS:ObjectData&gt;\r\n        &lt;SecureFtpTask\r\n          StorageAction=\"DeleteFtpFile\"\r\n          FileOverwriteAction=\"OverwriteAll\"\r\n          TreatRegXForFullPath=\"False\"\r\n          ContinueOnError=\"False\"\r\n...................\r\n...................\r\n...................            \r\n            PrefixTimestamp=\"False\" \/&gt;\r\n      &lt;\/DTS:ObjectData&gt;\r\n    &lt;\/DTS:Executable&gt;             \r\n             *\/\r\n\r\n            \/\/Application.\r\n\r\n            \/* use below code to save to disk file \r\n            var app = new Microsoft.SqlServer.Dts.Runtime.Application();\r\n            var filepath = @\"c:\\temp\\demo.dtsx\";\r\n            app.SaveToXml(filepath, p, null);\r\n\r\n            --load from disk to memory\r\n            p = app.LoadPackage(filepath, null);\r\n\r\n            *\/\r\n            var status = p.Execute();\r\n\r\n            if (status != DTSExecResult.Success)\r\n            {\r\n                var errs = \"\";\r\n                foreach (var e in p.Errors)\r\n                {\r\n                    errs = errs + string.Format(\"Source={0}, Err={1}\", e.Source, e.Description) + \"\\r\\n\";\r\n                }\r\n\r\n                throw new Exception(\"Package status was &gt;&gt; \" + status + \" &gt;&gt; \" + errs);\r\n            }\r\n\r\n            Console.WriteLine(\"Execution Completed... Press any key to exit!!!\");\r\n            Console.ReadKey();\r\n        }\r\n        private static void Create_SSIS_Dataflow_Source_Component_Demo()\r\n        {\r\n            var p = new Microsoft.SqlServer.Dts.Runtime.Package();\r\n\r\n\r\n            \/*============ STEP-1: Create Dataflow Task =========== *\/\r\n\r\n            var tsk1 = p.Executables.Add(\"STOCK:PipelineTask\") as TaskHost;\r\n            var dataFlowTask = tsk1.InnerObject as MainPipe;\r\n\r\n            \/*============ STEP-2: Create Connection =========== *\/\r\n            var conn1 = p.Connections.Add(\"ZS-HTTP\");\r\n            conn1.Name = \"MyConnection\";\r\n            conn1.ConnectionString = \"Url=https:\/\/httpbin.org\/get;CredentialType=Basic;UserName=test;Password=test123\";\r\n\r\n\r\n            \/*============ STEP-3: Create Source =========== *\/\r\n            var sourceComponent = dataFlowTask.ComponentMetaDataCollection.New();\r\n\r\n            try\r\n            {\r\n                sourceComponent.ComponentClassID = \"ZappySys.JsonSource\";\r\n                var sourceInstance = sourceComponent.Instantiate();\r\n                sourceInstance.ProvideComponentProperties();\r\n\r\n                sourceComponent.Name = \"MySource\";\r\n                \/**** Special Case for JSON Source - if user wants connection to use then we create Runtime connection. For all other components this is always created when ProvideComponentProperties() is called*\/\r\n                if (sourceComponent.RuntimeConnectionCollection.Count &lt;= 0)\r\n                {\r\n                    var dtsRuntimeConnection = sourceComponent.RuntimeConnectionCollection.New();\r\n                    dtsRuntimeConnection.Name = \"Connection\"; \r\n                    \/\/dtsRuntimeConnection.Description = \"This can be ZS-HTTP, ZS-OAUTH or ZS-SALESFORCE\";\r\n                }\r\n                sourceComponent.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.GetExtendedInterface(conn1);\r\n                sourceComponent.RuntimeConnectionCollection[0].ConnectionManagerID = conn1.ID;\r\n\r\n                sourceInstance.SetComponentProperty(\"UseConnection\", true);\/\/JsonSource specific -- for all other components connection always used\r\n                sourceInstance.SetComponentProperty(\"DirectPath\", \"https:\/\/httpbin.org\/basic-auth\/test\/test123\");\r\n                \/\/sourceInstance.SetComponentProperty(\"Filter\", \"$.value[*]\");\r\n\r\n                \/\/make connection active before next step\r\n                sourceInstance.AcquireConnections(null);\r\n\r\n                \/\/after connection + props set ... call ReInitialize meta... it creates columns \/ output \/ input etc\r\n                sourceInstance.ReinitializeMetaData(); \r\n            }\r\n            catch (COMException ex)\r\n            {\r\n                throw new Exception(\"Error Happened ==&gt; \" + sourceComponent.GetErrorDescription(ex.ErrorCode));\r\n            }\r\n\r\n\r\n\r\n\r\n            \/*============ STEP-4: Create Target (without Reinitialize) =========== *\/\r\n\r\n            var targetComponent = dataFlowTask.ComponentMetaDataCollection.New();\r\n            CManagedComponentWrapper targetInstance=null;\r\n            try\r\n            {\r\n                targetComponent.ComponentClassID = \"ZappySys.TrashDestination\";\r\n                targetInstance = targetComponent.Instantiate();\r\n                targetInstance.ProvideComponentProperties();\r\n\r\n                targetComponent.Name = \"MyDestination\";\r\n\r\n                targetInstance.SetComponentProperty(\"SaveDataToFile\", true);\r\n                targetInstance.SetComponentProperty(\"FilePath\", @\"c:\\temp\\dump.txt\");\r\n                targetInstance.SetComponentProperty(\"OverwriteFileIfExists\", true);\r\n\r\n                \/\/--- Trash destination doesnt have connection but incase destination uses connection... set below way\r\n                \/\/if you have connection then set this way\r\n                \/\/var conn2 = p.Connections.Add(\".....\"); \/\/Creation name i.e. ZS-HTTP\r\n                \/\/conn2.Name = \"MyConnection2\";\r\n                \/\/conn3.ConnectionString = \"Url=https:\/\/httpbin.org\/get;CredentialType=Basic;UserName=test;Password=test123\";\r\n                \/\/if (targetComponent.RuntimeConnectionCollection.Count &lt;= 0)\r\n                \/\/{\r\n                \/\/    var dtsRuntimeConnection = targetComponent.RuntimeConnectionCollection.New();\r\n                \/\/    dtsRuntimeConnection.Name = \"Connection\"; \r\n                \/\/}\r\n                \/\/sourceComponent.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.GetExtendedInterface(conn2);\r\n                \/\/sourceComponent.RuntimeConnectionCollection[0].ConnectionManagerID = conn2.ID;\r\n                \/\/make connection active before next step\r\n                \/\/targetInstance.AcquireConnections(null);\r\n            }\r\n            catch (COMException ex)\r\n            {\r\n                throw new Exception(\"Error Happened ==&gt; \" + targetComponent.GetErrorDescription(ex.ErrorCode));\r\n            }\r\n\r\n            \/*============ STEP-5: Connect Source to Target =========== *\/\r\n\r\n            \/\/before we call reintializemetadata for dest .. lets attach src and dest so .. dest can use virtual inputs if needed\r\n            var output = sourceComponent.OutputCollection[0]; \/\/to make it simple lets pick first output but possible component can have more outputs\r\n            var input = targetComponent.InputCollection[0];\r\n\r\n            dataFlowTask.PathCollection.New().AttachPathAndPropagateNotifications(output, input);\r\n\r\n            \/*============ STEP-6: Configure Target =========== *\/\r\n            try\r\n            {\r\n                \/\/after connection + props set and source to target attached... call ReInitialize meta... it creates columns \/ output \/ input etc\r\n                targetInstance.ReinitializeMetaData(); \r\n            }\r\n            catch (COMException ex)\r\n            {\r\n                throw new Exception(\"Error Happened ==&gt; \" + targetComponent.GetErrorDescription(ex.ErrorCode));\r\n            }\r\n\r\n\r\n            \/*============ STEP-6: Save Package =========== *\/\r\n\r\n            \/\/* use below code to save to disk file \r\n            var app = new Microsoft.SqlServer.Dts.Runtime.Application();\r\n            var filepath = @\"c:\\temp\\demo.dtsx\";\r\n            app.SaveToXml(filepath, p, null);\r\n\r\n            \/*============ STEP-7: Load Package =========== *\/\r\n            \/\/--load from disk to memory\r\n            p = app.LoadPackage(filepath, null);\r\n\r\n            \/\/*\/\r\n\r\n            \/*============ STEP-8: Execute Package =========== *\/\r\n            var status = p.Execute();\r\n\r\n            \/*============ STEP-9: Print execution status \/ log =========== *\/\r\n            if (status != DTSExecResult.Success)\r\n            {\r\n                var errs = \"\";\r\n                foreach (var e in p.Errors)\r\n                {\r\n                    errs = errs + string.Format(\"Source={0}, Err={1}\", e.Source, e.Description) + \"\\r\\n\";\r\n                }\r\n\r\n                throw new Exception(\"Package status was &gt;&gt; \" + status + \" &gt;&gt; \" + errs);\r\n            }\r\n\r\n            Console.WriteLine(\"Execution Completed... Press any key to exit!!!\");\r\n            Console.ReadKey();\r\n        }\r\n\r\n        private static void Create_SSIS_Variable_Demo()\r\n        {\r\n            var p = new Microsoft.SqlServer.Dts.Runtime.Package();\r\n            \r\n            p.Variables.Add(\"MyVariableName1\", false, \"User\", \"Some value\");\r\n        }\r\n\r\n        private static void Create_SSIS_Connection_Demo()\r\n        {\r\n            var p = new Microsoft.SqlServer.Dts.Runtime.Package();\r\n\r\n            var conn1 = p.Connections.Add(\"ZS-SFTP\");\r\n            conn1.Name = \"MySftpConnection\";\r\n            conn1.ConnectionString = \"Protocol=Sftp;ServerName=127.0.0.1;Port=0;LogonType=Normal;UserName=zstest;Password=zstest123\";\r\n\r\n        }\r\n\r\n        private static void Create_SSIS_Connect_Tasks_Demo()\r\n        {\r\n            var p = new Microsoft.SqlServer.Dts.Runtime.Package();\r\n\r\n            var SFTP_TASK = \"ZappySys.SecureFtpTask\";\r\n\r\n            var tsk1 = p.Executables.Add(SFTP_TASK) as TaskHost;\r\n            tsk1.Name = \"SFTP_Task1\";\r\n            \/*set some props - see Create_SSIS_Controlflow_Task_Demo *\/\r\n\r\n            var tsk2 = p.Executables.Add(SFTP_TASK) as TaskHost;\r\n            tsk2.Name = \"SFTP_Task2\";\r\n            \/*set some props - see Create_SSIS_Controlflow_Task_Demo *\/\r\n            \r\n            \/\/add link between task1--&gt;task2\r\n            var pc = p.PrecedenceConstraints.Add(tsk1, tsk2);\r\n            pc.EvalOp = DTSPrecedenceEvalOp.Constraint;\r\n            pc.Value = DTSExecResult.Success;\r\n            pc.LogicalAnd = true; \/\/only useful if multiple inputs coming and you want all previous steps to be Green vs Any One Green .. if its any use LogicalAnd=False\r\n\r\n            \/\/If you need to connect with expression use below\r\n            \/\/pc.EvalOp = DTSPrecedenceEvalOp.ExpressionAndConstraint;\r\n            \/\/pc.Expression = \"@SomeVariable == true\";\r\n        }\r\n\r\n       \r\n\r\n     \r\n    }\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this post, we will see how to create SSIS Package Programmatically to use ZappySys SSIS PowerPack. This blog post assumes you have basic knowledge of Programming language like C# and you have installed Visual Studio Express or a similar product (VS Code not supported). Add SSIS Dll References The very first thing is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9503,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,138,11],"tags":[590,294,12],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>How to create SSIS Package Programmatically (Add \/ Execute Tasks) | ZappySys Blog<\/title>\r\n<meta name=\"description\" content=\"Learn how to programmatically create SSIS packages using C#. Step-by-step guide to add connections, execute tasks, and handle errors dynamically in your ETL.\" \/>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"How to create SSIS Package Programmatically (Add \/ Execute Tasks) | ZappySys Blog\" \/>\r\n<meta property=\"og:description\" content=\"Learn how to programmatically create SSIS packages using C#. Step-by-step guide to add connections, execute tasks, and handle errors dynamically in your ETL.\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/\" \/>\r\n<meta property=\"og:site_name\" content=\"ZappySys Blog\" \/>\r\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/ZappySys\/\" \/>\r\n<meta property=\"article:published_time\" content=\"2021-12-31T15:00:01+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2025-12-11T11:23:03+00:00\" \/>\r\n<meta property=\"og:image\" content=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio.png\" \/>\r\n\t<meta property=\"og:image:width\" content=\"778\" \/>\r\n\t<meta property=\"og:image:height\" content=\"604\" \/>\r\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\r\n<meta name=\"author\" content=\"ZappySys\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/zappysys\/\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ZappySys\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/\",\"url\":\"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/\",\"name\":\"How to create SSIS Package Programmatically (Add \/ Execute Tasks) | ZappySys Blog\",\"isPartOf\":{\"@id\":\"https:\/\/zappysys.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio.png\",\"datePublished\":\"2021-12-31T15:00:01+00:00\",\"dateModified\":\"2025-12-11T11:23:03+00:00\",\"author\":{\"@id\":\"https:\/\/zappysys.com\/blog\/#\/schema\/person\/2756c237457fbc95d82cb38962f81f82\"},\"description\":\"Learn how to programmatically create SSIS packages using C#. Step-by-step guide to add connections, execute tasks, and handle errors dynamically in your ETL.\",\"breadcrumb\":{\"@id\":\"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/#primaryimage\",\"url\":\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio.png\",\"contentUrl\":\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio.png\",\"width\":778,\"height\":604},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/zappysys.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to create SSIS Package Programmatically (Add \/ Execute Tasks)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/zappysys.com\/blog\/#website\",\"url\":\"https:\/\/zappysys.com\/blog\/\",\"name\":\"ZappySys Blog\",\"description\":\"SSIS \/ ODBC Drivers \/ API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/zappysys.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/zappysys.com\/blog\/#\/schema\/person\/2756c237457fbc95d82cb38962f81f82\",\"name\":\"ZappySys\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zappysys.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5c9be148088ba9b8af8e955c5f7c22b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5c9be148088ba9b8af8e955c5f7c22b5?s=96&d=mm&r=g\",\"caption\":\"ZappySys\"},\"sameAs\":[\"http:\/\/www.zappysys.com\/\",\"https:\/\/www.facebook.com\/ZappySys\/\",\"https:\/\/twitter.com\/https:\/\/twitter.com\/zappysys\/\"],\"url\":\"https:\/\/zappysys.com\/blog\/author\/admin\/\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create SSIS Package Programmatically (Add \/ Execute Tasks) | ZappySys Blog","description":"Learn how to programmatically create SSIS packages using C#. Step-by-step guide to add connections, execute tasks, and handle errors dynamically in your ETL.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/","og_locale":"en_US","og_type":"article","og_title":"How to create SSIS Package Programmatically (Add \/ Execute Tasks) | ZappySys Blog","og_description":"Learn how to programmatically create SSIS packages using C#. Step-by-step guide to add connections, execute tasks, and handle errors dynamically in your ETL.","og_url":"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/","og_site_name":"ZappySys Blog","article_author":"https:\/\/www.facebook.com\/ZappySys\/","article_published_time":"2021-12-31T15:00:01+00:00","article_modified_time":"2025-12-11T11:23:03+00:00","og_image":[{"width":778,"height":604,"url":"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio.png","type":"image\/png"}],"author":"ZappySys","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/zappysys\/","twitter_misc":{"Written by":"ZappySys","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/","url":"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/","name":"How to create SSIS Package Programmatically (Add \/ Execute Tasks) | ZappySys Blog","isPartOf":{"@id":"https:\/\/zappysys.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/#primaryimage"},"image":{"@id":"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/#primaryimage"},"thumbnailUrl":"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio.png","datePublished":"2021-12-31T15:00:01+00:00","dateModified":"2025-12-11T11:23:03+00:00","author":{"@id":"https:\/\/zappysys.com\/blog\/#\/schema\/person\/2756c237457fbc95d82cb38962f81f82"},"description":"Learn how to programmatically create SSIS packages using C#. Step-by-step guide to add connections, execute tasks, and handle errors dynamically in your ETL.","breadcrumb":{"@id":"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/#primaryimage","url":"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio.png","contentUrl":"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2021\/12\/create-ssis-package-programatically-add-dll-reference-visual-studio.png","width":778,"height":604},{"@type":"BreadcrumbList","@id":"https:\/\/zappysys.com\/blog\/create-ssis-package-programmatically-add-execute-connections-tasks\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/zappysys.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to create SSIS Package Programmatically (Add \/ Execute Tasks)"}]},{"@type":"WebSite","@id":"https:\/\/zappysys.com\/blog\/#website","url":"https:\/\/zappysys.com\/blog\/","name":"ZappySys Blog","description":"SSIS \/ ODBC Drivers \/ API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/zappysys.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/zappysys.com\/blog\/#\/schema\/person\/2756c237457fbc95d82cb38962f81f82","name":"ZappySys","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zappysys.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5c9be148088ba9b8af8e955c5f7c22b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c9be148088ba9b8af8e955c5f7c22b5?s=96&d=mm&r=g","caption":"ZappySys"},"sameAs":["http:\/\/www.zappysys.com\/","https:\/\/www.facebook.com\/ZappySys\/","https:\/\/twitter.com\/https:\/\/twitter.com\/zappysys\/"],"url":"https:\/\/zappysys.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/posts\/9500"}],"collection":[{"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/comments?post=9500"}],"version-history":[{"count":4,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/posts\/9500\/revisions"}],"predecessor-version":[{"id":9563,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/posts\/9500\/revisions\/9563"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/media\/9503"}],"wp:attachment":[{"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/media?parent=9500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/categories?post=9500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/tags?post=9500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}