<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Initialize SSIS Variables from a Database Table</title>
	<atom:link href="http://blog.boxedbits.com/archives/8/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.boxedbits.com/archives/8</link>
	<description>( ... more specifically about BI with Microsoft products )</description>
	<lastBuildDate>Fri, 16 Jul 2010 18:42:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Robert</title>
		<link>http://blog.boxedbits.com/archives/8/comment-page-1#comment-3456</link>
		<dc:creator>Robert</dc:creator>
		<pubDate>Tue, 23 Mar 2010 10:58:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.boxedbits.com/archives/8#comment-3456</guid>
		<description>Don&#039;t forget that the Mor% - sorry, the Cre&amp; - sorry, the swell guys at Microsoft managed to localize the name of the default namespace. I&#039;d bet this accounts for at least some of the other commenters&#039; problems.

And by the way, I prefer doing this in a data flow like:
Public Class ScriptMain
    Inherits UserComponent

    Dim oRegEx As Regex

    Public Sub New()
        oRegEx = New Regex(&quot;[^a-zA-Z0-9_]+&quot;)
    End Sub

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
        Dim iKey As Int32
        Dim sName As String
        Dim vars As IDTSVariables90 = Nothing

        If Not Row.ikey_IsNull AndAlso Not Row.gname_IsNull AndAlso Not Row.tname_IsNull Then
            iKey = CType(Row.ikey, Int32)
            sName = oRegEx.Replace(Row.gname, &quot;_&quot;).Replace(&quot;__&quot;, &quot;_&quot;) &amp; &quot;::&quot; &amp; oRegEx.Replace(Row.tname, &quot;_&quot;).Replace(&quot;__&quot;, &quot;_&quot;)
            Try
                Me.VariableDispenser.LockForWrite(sName)
                Me.VariableDispenser.GetVariables(vars)
            Catch ex As Exception
                Me.ComponentMetaData.FireWarning(1001, &quot;Parameter Reader&quot;, sName &amp; &quot; not found.&quot;, Nothing, 0)
            End Try
            If Not vars Is Nothing Then
                Try
                    vars(sName).Value = iKey
                    Me.ComponentMetaData.IncrementPipelinePerfCounter(103, 1)
                Catch ex As Exception
                End Try
                vars.Unlock()
            End If
        End If
    End Sub

End Class

- Note I thought performance impact of locking/unlocking the vars one by one is negligible, and that this pipeline comes with the fields ikey int, gname wstr and tname wstr, and that I only needed integer parameters in this case.
- Also note the error handling is not clean - am fighting the docs tring to find the specific exception type thrown for a missing name and losing.
- Also note the names in the database are not under my control, hence the sanitizing RegEx.</description>
		<content:encoded><![CDATA[<p>Don&#8217;t forget that the Mor% &#8211; sorry, the Cre&amp; &#8211; sorry, the swell guys at Microsoft managed to localize the name of the default namespace. I&#8217;d bet this accounts for at least some of the other commenters&#8217; problems.</p>
<p>And by the way, I prefer doing this in a data flow like:<br />
Public Class ScriptMain<br />
    Inherits UserComponent</p>
<p>    Dim oRegEx As Regex</p>
<p>    Public Sub New()<br />
        oRegEx = New Regex(&#8220;[^a-zA-Z0-9_]+&#8221;)<br />
    End Sub</p>
<p>    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)<br />
        Dim iKey As Int32<br />
        Dim sName As String<br />
        Dim vars As IDTSVariables90 = Nothing</p>
<p>        If Not Row.ikey_IsNull AndAlso Not Row.gname_IsNull AndAlso Not Row.tname_IsNull Then<br />
            iKey = CType(Row.ikey, Int32)<br />
            sName = oRegEx.Replace(Row.gname, &#8220;_&#8221;).Replace(&#8220;__&#8221;, &#8220;_&#8221;) &amp; &#8220;::&#8221; &amp; oRegEx.Replace(Row.tname, &#8220;_&#8221;).Replace(&#8220;__&#8221;, &#8220;_&#8221;)<br />
            Try<br />
                Me.VariableDispenser.LockForWrite(sName)<br />
                Me.VariableDispenser.GetVariables(vars)<br />
            Catch ex As Exception<br />
                Me.ComponentMetaData.FireWarning(1001, &#8220;Parameter Reader&#8221;, sName &amp; &#8221; not found.&#8221;, Nothing, 0)<br />
            End Try<br />
            If Not vars Is Nothing Then<br />
                Try<br />
                    vars(sName).Value = iKey<br />
                    Me.ComponentMetaData.IncrementPipelinePerfCounter(103, 1)<br />
                Catch ex As Exception<br />
                End Try<br />
                vars.Unlock()<br />
            End If<br />
        End If<br />
    End Sub</p>
<p>End Class</p>
<p>- Note I thought performance impact of locking/unlocking the vars one by one is negligible, and that this pipeline comes with the fields ikey int, gname wstr and tname wstr, and that I only needed integer parameters in this case.<br />
- Also note the error handling is not clean &#8211; am fighting the docs tring to find the specific exception type thrown for a missing name and losing.<br />
- Also note the names in the database are not under my control, hence the sanitizing RegEx.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom VdP</title>
		<link>http://blog.boxedbits.com/archives/8/comment-page-1#comment-3212</link>
		<dc:creator>Tom VdP</dc:creator>
		<pubDate>Thu, 17 Sep 2009 08:41:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.boxedbits.com/archives/8#comment-3212</guid>
		<description>Make sure that the variable names in the package and in the table match exactly including casing: if you have a “myVariable” in the table and a “MyVariable” in the package then they will not match.
Also, the Variables collection is empty because you do not supply any variables in the script component’s ReadOnlyVariables or ReadWriteVariables, which is good because the script is supposed to be generic. It looks for any variable defined in the package.</description>
		<content:encoded><![CDATA[<p>Make sure that the variable names in the package and in the table match exactly including casing: if you have a “myVariable” in the table and a “MyVariable” in the package then they will not match.<br />
Also, the Variables collection is empty because you do not supply any variables in the script component’s ReadOnlyVariables or ReadWriteVariables, which is good because the script is supposed to be generic. It looks for any variable defined in the package.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AK</title>
		<link>http://blog.boxedbits.com/archives/8/comment-page-1#comment-3208</link>
		<dc:creator>AK</dc:creator>
		<pubDate>Wed, 16 Sep 2009 14:11:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.boxedbits.com/archives/8#comment-3208</guid>
		<description>I tried the samething in my script task. It neither returns any error nor returns desired results. While debugging I found the variables collection count is always getting displayed as 0 inspite of variables declared at the package level scope. Any help will be appreciated.

Thanks,
AK</description>
		<content:encoded><![CDATA[<p>I tried the samething in my script task. It neither returns any error nor returns desired results. While debugging I found the variables collection count is always getting displayed as 0 inspite of variables declared at the package level scope. Any help will be appreciated.</p>
<p>Thanks,<br />
AK</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom VdP</title>
		<link>http://blog.boxedbits.com/archives/8/comment-page-1#comment-2595</link>
		<dc:creator>Tom VdP</dc:creator>
		<pubDate>Thu, 12 Feb 2009 16:10:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.boxedbits.com/archives/8#comment-2595</guid>
		<description>Pedro,
The idea is that all logic is contained within a single SQL Server database.  When deploying to &quot;server xyz&quot; then the parameter values stored in &quot;server xyz&quot; will be used.  That is much cleaner than having to distribute a configuration file with the SSIS packages and adapt their contents per specific deployment.
Of course, there is one caveat: you have to make sure the packages connect to the correct database.  This is done by &quot;overruling&quot; the data source connection strings in the SQL Server Agent: it is one of the job step properties.
There are probably a lot of scenario&#039;s where using configuration files is the better approach.  But for a project where packages are run via SQL Agent jobs, I prefer the approach described above.</description>
		<content:encoded><![CDATA[<p>Pedro,<br />
The idea is that all logic is contained within a single SQL Server database.  When deploying to &#8220;server xyz&#8221; then the parameter values stored in &#8220;server xyz&#8221; will be used.  That is much cleaner than having to distribute a configuration file with the SSIS packages and adapt their contents per specific deployment.<br />
Of course, there is one caveat: you have to make sure the packages connect to the correct database.  This is done by &#8220;overruling&#8221; the data source connection strings in the SQL Server Agent: it is one of the job step properties.<br />
There are probably a lot of scenario&#8217;s where using configuration files is the better approach.  But for a project where packages are run via SQL Agent jobs, I prefer the approach described above.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PedroCGD</title>
		<link>http://blog.boxedbits.com/archives/8/comment-page-1#comment-2409</link>
		<dc:creator>PedroCGD</dc:creator>
		<pubDate>Tue, 06 Jan 2009 00:11:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.boxedbits.com/archives/8#comment-2409</guid>
		<description>Dear Friend,
Good post and blog.
But tell me why you need all this using script, you you have SSIS Package Configurations? 
Or you can use only SQL Task to get the values to a database table and store in a SSIS variable.
Regards,
Pedro</description>
		<content:encoded><![CDATA[<p>Dear Friend,<br />
Good post and blog.<br />
But tell me why you need all this using script, you you have SSIS Package Configurations?<br />
Or you can use only SQL Task to get the values to a database table and store in a SSIS variable.<br />
Regards,<br />
Pedro</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom VdP</title>
		<link>http://blog.boxedbits.com/archives/8/comment-page-1#comment-1653</link>
		<dc:creator>Tom VdP</dc:creator>
		<pubDate>Fri, 15 Aug 2008 15:42:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.boxedbits.com/archives/8#comment-1653</guid>
		<description>If you want to assign a value from the database table to an SSIS variable of, say, type Int32 then you will have to cast &lt;i&gt;de.Value&lt;/i&gt; in the code above to integer.  Otherwise you get an error: &lt;i&gt;Variables may not change type during execution. Variable types are strict, except for variables of type Object&lt;/i&gt;.</description>
		<content:encoded><![CDATA[<p>If you want to assign a value from the database table to an SSIS variable of, say, type Int32 then you will have to cast <i>de.Value</i> in the code above to integer.  Otherwise you get an error: <i>Variables may not change type during execution. Variable types are strict, except for variables of type Object</i>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: red</title>
		<link>http://blog.boxedbits.com/archives/8/comment-page-1#comment-1632</link>
		<dc:creator>red</dc:creator>
		<pubDate>Wed, 13 Aug 2008 19:01:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.boxedbits.com/archives/8#comment-1632</guid>
		<description>Very nice. Just wondering what exactly you mean by &quot;all the parameters are string types&quot;. Are you talking about the parameters in database table only or both in the table as well as the variables in SSIS package? Could the package variables be of different datatypes?</description>
		<content:encoded><![CDATA[<p>Very nice. Just wondering what exactly you mean by &#8220;all the parameters are string types&#8221;. Are you talking about the parameters in database table only or both in the table as well as the variables in SSIS package? Could the package variables be of different datatypes?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom VdP</title>
		<link>http://blog.boxedbits.com/archives/8/comment-page-1#comment-1507</link>
		<dc:creator>Tom VdP</dc:creator>
		<pubDate>Wed, 06 Aug 2008 13:01:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.boxedbits.com/archives/8#comment-1507</guid>
		<description>It is probably the check for the existence of the variable in the &lt;i&gt;While sqlResult.Read()&lt;/i&gt;-loop that returns false.  Variable names are case sensitive, so make sure the value of the ParameterName in the table matches the name of the SSIS parameter exactly.
If this does not help you will have to resort to adding debugging messageboxes.</description>
		<content:encoded><![CDATA[<p>It is probably the check for the existence of the variable in the <i>While sqlResult.Read()</i>-loop that returns false.  Variable names are case sensitive, so make sure the value of the ParameterName in the table matches the name of the SSIS parameter exactly.<br />
If this does not help you will have to resort to adding debugging messageboxes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin</title>
		<link>http://blog.boxedbits.com/archives/8/comment-page-1#comment-1506</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Wed, 06 Aug 2008 12:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.boxedbits.com/archives/8#comment-1506</guid>
		<description>I have changed the name of the db connection in the script and when I run the script it executes successfully but it does not change the variables to the ones stored within the database (SQL Server 2005). The db schema is below.  I figure it is something small, but I have yet to pinpoint it. Let me know what additional information may be useful.  

[dbo].[SSISCubeAutomationVariables]( 
[OLAPdbName] [varchar] (100) NOT NULL, 
[Month] [varchar] (20) NULL, 
[Year] [varchar] (10) NULL, 
[ParameterName] [varchar] (100) NOT NULL, 
[ParameterValue] [varchar] (4000) NULL, 
[Description] [varchar] (4000) NULL )
ON [PRIMARY]</description>
		<content:encoded><![CDATA[<p>I have changed the name of the db connection in the script and when I run the script it executes successfully but it does not change the variables to the ones stored within the database (SQL Server 2005). The db schema is below.  I figure it is something small, but I have yet to pinpoint it. Let me know what additional information may be useful.  </p>
<p>[dbo].[SSISCubeAutomationVariables](<br />
[OLAPdbName] [varchar] (100) NOT NULL,<br />
[Month] [varchar] (20) NULL,<br />
[Year] [varchar] (10) NULL,<br />
[ParameterName] [varchar] (100) NOT NULL,<br />
[ParameterValue] [varchar] (4000) NULL,<br />
[Description] [varchar] (4000) NULL )<br />
ON [PRIMARY]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom VdP</title>
		<link>http://blog.boxedbits.com/archives/8/comment-page-1#comment-1487</link>
		<dc:creator>Tom VdP</dc:creator>
		<pubDate>Tue, 05 Aug 2008 20:26:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.boxedbits.com/archives/8#comment-1487</guid>
		<description>Kevin, I cannot disclose the package in which I use this code.  But if you give some more details about the &quot;issues&quot; you are having I will be glad to help.</description>
		<content:encoded><![CDATA[<p>Kevin, I cannot disclose the package in which I use this code.  But if you give some more details about the &#8220;issues&#8221; you are having I will be glad to help.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
