{"id":123,"date":"2008-07-07T16:36:28","date_gmt":"2008-07-07T16:36:28","guid":{"rendered":"https:\/\/www.wapshere.com\/missmiis\/?page_id=123"},"modified":"2008-07-09T14:22:42","modified_gmt":"2008-07-09T14:22:42","slug":"vbscript-function-runssis","status":"publish","type":"page","link":"https:\/\/www.wapshere.com\/missmiis\/vbscript-function-runssis","title":{"rendered":"vbscript: Function RunSSIS"},"content":{"rendered":"<p>Run a SQL 2005 SSIS package from vbscript. Useful if you need to do some table manipulation prior to an MA import &#8211; such as when generating a <a href=\"https:\/\/www.wapshere.com\/missmiis\/?p=12\" target=\"_self\">Delta table<\/a>.<\/p>\n<p>Note the comment in the script about using objExec.stdOut. I employed a wait loop and objExec.Status before, but I had a problem with certain SSIS packages not returning a status to vbscript. even though they had completed. I have found this method to be more stable.<\/p>\n<p>\u00c2\u00a0<\/p>\n<blockquote><p>Const MIIS_FOLDER = &#8220;C:\\Program Files\\Microsoft Identity Integration Server&#8221;<br \/>\nConst DB_CONNECT_STRING = &#8220;Provider=SQLOLEDB;Data Source=(local);Initial Catalog=<em>DB-name<\/em>;Integrated Security=SSPI&#8221;<br \/>\nConst SSIS_SUCCESS = &#8220;The package execution returned DTSER_SUCCESS&#8221;<br \/>\nConst SSIS_LOG_FILE = &#8220;<em>log_file_path<\/em>&#8221;<br \/>\nConst ForReading = 1<br \/>\nConst ForWriting = 2<br \/>\nConst ForAppending = 8<br \/>\nConst Unicode = -1<\/p>\n<p>&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n&#8216;\u00c2\u00a0 Function RunSSIS<br \/>\n&#8216;\u00c2\u00a0 + Call a SQL SSIS package<br \/>\n&#8216;\u00c2\u00a0 + Returns 0 for success<br \/>\n&#8216;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>Function RunSSIS(packageName)<br \/>\n\u00c2\u00a0 Dim strCmd, strOutput<br \/>\n\u00c2\u00a0 Dim objShell, objExec<br \/>\n\u00c2\u00a0 Dim iCount<br \/>\nDim SSISLogFile, objFS, objSSISLogFile<\/p>\n<p>Set objFS = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br \/>\nSet objSSISLogFile = objFS.OpenTextFile(SSIS_LOG_FILE, ForWriting, TRUE)<\/p>\n<p>\u00c2\u00a0 WriteLog &#8220;Running SSIS package &#8221; &amp; packageName<br \/>\n\u00c2\u00a0<br \/>\n\u00c2\u00a0 strCmd = &#8220;dtexec \/DTS &#8220;&#8221;\\MSDB\\&#8221; &amp; packageName &amp; &#8220;&#8221;&#8221; \/SERVER\u00c2\u00a0<em>server-name<\/em> \/MAXCONCURRENT &#8220;&#8221; -1 &#8220;&#8221; \/CHECKPOINTING OFF\u00c2\u00a0 \/REPORTING V&#8221;<br \/>\n\u00c2\u00a0 Set objShell = CreateObject(&#8220;WScript.Shell&#8221;)<\/p>\n<p>\u00c2\u00a0 Set objExec = objShell.Exec(strCmd)<br \/>\n&#8216; &#8211;need to use objExec.stdOut straight after Exec to force vbscript to wait<br \/>\n\u00c2\u00a0 strOutput = objExec.stdOut.ReadAll<\/p>\n<p>\u00c2\u00a0 If InStr(strOutput, SSIS_SUCCESS) &gt; 0 Then<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 RunSSIS = 0<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 WriteLog &#8220;Package completed successfully.&#8221;<br \/>\n\u00c2\u00a0 Else<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 RunSSIS = 1<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 WriteLog &#8220;Package failed. See &#8221; &amp; SSISLogFileName &amp; &#8221; for the full output.&#8221;<br \/>\n\u00c2\u00a0 End If<br \/>\n\u00c2\u00a0<br \/>\n\u00c2\u00a0 objSSISLogFile.Write(strOutput)<\/p>\n<p>End Function<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Run a SQL 2005 SSIS package from vbscript. Useful if you need to do some table manipulation prior to an MA import &#8211; such as when generating a Delta table. Note the comment in the script about using objExec.stdOut. I employed a wait loop and objExec.Status before, but I had a problem with certain SSIS&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"jetpack_post_was_ever_published":false,"footnotes":""},"class_list":["post-123","page","type-page","status-publish","hentry"],"jetpack_shortlink":"https:\/\/wp.me\/Pkp1o-1Z","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/pages\/123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/comments?post=123"}],"version-history":[{"count":0,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/pages\/123\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/media?parent=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}