<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.developerdotstar.com/community" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>developer.* Blogs - Reusable Functions for Reading and Writing Variables in SSIS Script Tasks - Comments</title>
 <link>http://www.developerdotstar.com/community/node/512</link>
 <description>Comments for &quot;Reusable Functions for Reading and Writing Variables in SSIS Script Tasks&quot;</description>
 <language>en</language>
<item>
 <title>Not Sure...</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-8485</link>
 <description>&lt;p&gt;Sorry, dave, but nothing jumps out at me other than the use of &quot;RdVar&quot; vs. &quot;ReadVariable&quot;--but that may have just been shorthand you&#039;re using for your example.&lt;/p&gt;
&lt;p&gt;One possibility does come to mind: is it possible that you&#039;ve also declared the &quot;SQL&quot; variable as read only in the Script Task dialog box? That might cause the behavior you describe. When using ReadVariable() and WriteVariable() you do not need to (and probably should not) declare the variables on the Script Task &quot;Edit&quot; dialog as available to the script.&lt;/p&gt;
&lt;p&gt;Hope that helps,&lt;br /&gt;
Dan&lt;/p&gt;
</description>
 <pubDate>Wed, 18 Apr 2007 09:08:57 -0700</pubDate>
 <dc:creator>Daniel Read</dc:creator>
 <guid isPermaLink="false">comment 8485 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Cannot write to package level variable</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-8470</link>
 <description>&lt;p&gt;Hi Dan,&lt;br /&gt;
I still cannot write to a package level variable in a Script Task.  I have 2 variables to create a SQL statement.&lt;/p&gt;
&lt;div class=&quot;codeblock&quot;&gt;
&lt;pre&gt;  Dim LastRecord As String, sSQL As String&lt;br /&gt;  LastRecord = CType(ReadVariable(&amp;quot;LastRow&amp;quot;), String)&lt;br /&gt;  sSQL = &amp;quot;SELECT * FROM MyTable WHERE RecID&amp;gt;&amp;quot; &amp;amp; LastRecord&lt;br /&gt;  WriteVariable(&amp;quot;SQL&amp;quot;, sSQL)&lt;br /&gt;  sSQL = CType(RdVar(&amp;quot;SQL&amp;quot;), String)&lt;br /&gt;  MsgBox(sSQL)&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I&#039;m able to read the value of LastRecord but when I appended to sSQL and call WriteVariable, the MsgBox () shows only the initial value of the Package variable (SQL).  Apparently it did not save it... any help???&lt;br /&gt;
Thanks in advance&lt;/p&gt;
</description>
 <pubDate>Tue, 17 Apr 2007 16:59:21 -0700</pubDate>
 <dc:creator>dave</dc:creator>
 <guid isPermaLink="false">comment 8470 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Slight variation when in Script Components</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-8455</link>
 <description>&lt;p&gt;Hi Daniel:&lt;br /&gt;
As the guest poster on 3/31/07 reported, I also found I had to modify the syntax slightly when using these functions in a data flow Script Component (these functions work perfectly in control flow Script Tasks). Don&#039;t know why there&#039;s a difference, but the &quot;vars&quot; object variable has to be declared as:&lt;br /&gt;
Dim vars As IDTSVariables90&lt;br /&gt;
And the VariableDispenser appears to be a static class owned by the Script Component. The &quot;Dts&quot; namespace causes an error, so the following works fine:&lt;br /&gt;
VariableDispenser.LockForRead(varName)&lt;/p&gt;
&lt;p&gt;BTW: One big reason for using these functions is because SSIS seems to mangle variable names passed to Script Components. When using the ReadOnlyVariables property of the Script Component, my variables (ImportFile_Name and ImportFile_Path) are missing their underscores within the Script Component&#039;s code (ImportFileName and ImportFilePath). This made it pretty hard to use the &quot;Me.Variables.&quot; as documented in online help. &lt;/p&gt;
&lt;p&gt;IMO, it&#039;s much cleaner and symmetric to use your functions for reading and writing variables, rather than relying on the ReadOnlyVariables and ReadWriteVariables properties. Code is much easier to read and understand when using your functions.&lt;/p&gt;
</description>
 <pubDate>Tue, 17 Apr 2007 07:36:24 -0700</pubDate>
 <dc:creator>MikeG</dc:creator>
 <guid isPermaLink="false">comment 8455 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Much appreceiated</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-8014</link>
 <description>&lt;p&gt;I have struggled for a week with the &#039;Can&#039;t get lock on variable&#039; error meesage.  I used your example and it all works fine.  Please send this to MS and tell them to include it in their documentation.&lt;/p&gt;
&lt;p&gt;Thanks again.&lt;/p&gt;
</description>
 <pubDate>Mon, 02 Apr 2007 09:53:28 -0700</pubDate>
 <dc:creator>Arthur Hill</dc:creator>
 <guid isPermaLink="false">comment 8014 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Variable naming in your procedure</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-8012</link>
 <description>&lt;p&gt;Everything I read says you have to refer to variables by their scope, such as &#039;User::DirectoryIncoming&#039; or &#039;System::Something&#039;.  In your example above you do not use the namespace qualifier.  Why?  Is it not necessary?&lt;/p&gt;
</description>
 <pubDate>Mon, 02 Apr 2007 09:14:30 -0700</pubDate>
 <dc:creator>Arthur Hill</dc:creator>
 <guid isPermaLink="false">comment 8012 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>ssis vars in scripts</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-7903</link>
 <description>&lt;p&gt;This stuff is a life-saver.  I could use your&lt;br /&gt;
Dts.VariableDispenser... for a scripts task, but could not for a script component which was reading a table. In your code above (both for read &amp;amp; write) I had to change the &quot;DTs&quot; to &quot;Me&quot;, then variable collection was changed also.  Here&#039;s the variantions on routines:&lt;/p&gt;
&lt;div class=&quot;codeblock&quot;&gt;
&lt;pre&gt;   Private Function ReadVariable(ByVal varName As String) As Object&lt;br /&gt;        Dim result As Object&lt;br /&gt;        Try&lt;br /&gt;            Dim vars As IDTSVariables90&lt;br /&gt;            Me.VariableDispenser.LockForRead(varName)&lt;br /&gt;            Me.VariableDispenser.GetVariables(vars)&lt;br /&gt;            Try&lt;br /&gt;                result = vars(varName).Value&lt;br /&gt;            Catch ex As Exception&lt;br /&gt;                Throw ex&lt;br /&gt;            Finally&lt;br /&gt;                vars.Unlock()&lt;br /&gt;            End Try&lt;br /&gt;        Catch ex As Exception&lt;br /&gt;            Throw ex&lt;br /&gt;        End Try&lt;br /&gt;        Return result&lt;br /&gt;    End Function&lt;br /&gt;&lt;br /&gt;    Private Sub WriteVariable(ByVal varName As String, ByVal varValue As Object)&lt;br /&gt;        Try&lt;br /&gt;            Dim vars As IDTSVariables90&lt;br /&gt;            Me.VariableDispenser.LockForWrite(varName)&lt;br /&gt;            Me.VariableDispenser.GetVariables(vars)&lt;br /&gt;            Try&lt;br /&gt;                vars(varName).Value = varValue&lt;br /&gt;            Catch ex As Exception&lt;br /&gt;                Throw ex&lt;br /&gt;            Finally&lt;br /&gt;                vars.Unlock()&lt;br /&gt;            End Try&lt;br /&gt;        Catch ex As Exception&lt;br /&gt;            Throw ex&lt;br /&gt;        End Try&lt;br /&gt;    End Sub&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is probably not the way to go, but maybe you can improve it.  Thanks much&lt;/p&gt;
</description>
 <pubDate>Sat, 31 Mar 2007 13:28:22 -0700</pubDate>
 <dc:creator>Guest</dc:creator>
 <guid isPermaLink="false">comment 7903 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>SSIS Scripting Shortcomings</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-7291</link>
 <description>&lt;p&gt;imFrustrated wrote: &quot;Is there no global scripting library that all script task have visibility to?&quot;&lt;/p&gt;
&lt;p&gt;Not as far as I can tell, there is not, no. The scripting integration at both design time and runtime is pretty clunky. You will do a lot of copying and pasting. When I was writing a lot of code in SSIS I had a  I hope this is one area they will be able to improve in future releases.&lt;/p&gt;
&lt;p&gt;Dan&lt;/p&gt;
&lt;p&gt;P.S.&lt;br /&gt;
See also &lt;a href=&quot;http://www.developerdotstar.com/community/node/333&quot; title=&quot;Fun With SSIS, Script Tasks, and the GAC&quot;&gt;this post&lt;/a&gt; for another example of what I mean by &quot;clunky.&quot;&lt;/p&gt;
</description>
 <pubDate>Sun, 18 Mar 2007 15:33:00 -0700</pubDate>
 <dc:creator>Daniel Read</dc:creator>
 <guid isPermaLink="false">comment 7291 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Just so I understand</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-7271</link>
 <description>&lt;p&gt;Nice blog post first of all.&lt;/p&gt;
&lt;p&gt;I am new to SSIS, is what you are saying that I have to copy these functions to each script task?  Is there no global scripting library that all script task have visibility to?&lt;/p&gt;
</description>
 <pubDate>Sat, 17 Mar 2007 07:28:21 -0700</pubDate>
 <dc:creator>imFurstrated</dc:creator>
 <guid isPermaLink="false">comment 7271 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Awesome!</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-5377</link>
 <description>&lt;p&gt;Thank you.&lt;/p&gt;
</description>
 <pubDate>Fri, 16 Feb 2007 12:08:43 -0800</pubDate>
 <dc:creator>Guest</dc:creator>
 <guid isPermaLink="false">comment 5377 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Doh.  Got it...</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-1990</link>
 <description>&lt;p&gt;As soon as I posted this I found the answer &lt;a href=&quot;http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=144734&amp;amp;SiteID=1&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
</description>
 <pubDate>Fri, 08 Dec 2006 07:32:44 -0800</pubDate>
 <dc:creator>Halvo</dc:creator>
 <guid isPermaLink="false">comment 1990 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Get variable names?</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-1989</link>
 <description>&lt;p&gt;Just curious if any of you know of any way to retrieve the names of the user variables which have been setup in a package (via VariableDispenser or any other object).&lt;/p&gt;
&lt;p&gt;We have a custom flow task, in which we want to read through each variable that the user has created looking for values with a specific pattern (UNC paths).  Considering we do not know which the variables have been named, we have no way of locking them for read.&lt;/p&gt;
&lt;p&gt;After a few days of research, we don&#039;t think there is a way, but it&#039;s hard for me to settle on that answer.&lt;/p&gt;
</description>
 <pubDate>Fri, 08 Dec 2006 06:34:33 -0800</pubDate>
 <dc:creator>Halvo</dc:creator>
 <guid isPermaLink="false">comment 1989 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Thanks</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-1591</link>
 <description>&lt;p&gt;Thank you.  I spent hours trying to figure out why I couldn&#039;t update a ReadWrite variable.  I still don&#039;t know why it won&#039;t work, but your solution worked perfectly.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
</description>
 <pubDate>Mon, 16 Oct 2006 06:12:43 -0700</pubDate>
 <dc:creator>Paul</dc:creator>
 <guid isPermaLink="false">comment 1591 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Need Help with Variables....</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-1572</link>
 <description>&lt;p&gt;I am trying to validate a flat file and insert the values in the SQL Table...It gets tricky here, If while validating, even one record has invalid field I have to abort the package that means no updates or inserts. If everything validates right I have to update the existing record and insert the new ones...&lt;br /&gt;
Problem I am running into is I thought I will declare a local variable count the # of errors everytime an error is raised and then decide what to do.As its a local variable my logic will not work as this variable gets initialized for every row.When I try to use the Package variables as I am using a Script component, I get the Read Write Lock error. I cannot use ur functions as they r for scripttask..Any suggestions from u on this...I have spent more than a week researching this...&lt;/p&gt;
</description>
 <pubDate>Sun, 08 Oct 2006 02:24:19 -0700</pubDate>
 <dc:creator>Guest</dc:creator>
 <guid isPermaLink="false">comment 1572 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Not Sure...</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-1552</link>
 <description>&lt;p&gt;Sorry, Vince, I don&#039;t know what to tell you. I&#039;ve never experienced either of the problems you&#039;re describing.&lt;/p&gt;
&lt;p&gt;You should not need to have a variable in the ReadWriteVariables if you&#039;re using the ReadVariable() and WriteVariable() functions to access it.&lt;/p&gt;
&lt;p&gt;Is the variable you&#039;re working with defined at package-level scope? I&#039;ve noticed that it&#039;s easy in BIDS to accidentally create a variable at the scope of a lower level container and not realize it.&lt;/p&gt;
&lt;p&gt;Sorry I couldn&#039;t be more help.&lt;/p&gt;
&lt;p&gt;Dan&lt;/p&gt;
</description>
 <pubDate>Tue, 03 Oct 2006 12:00:29 -0700</pubDate>
 <dc:creator>Daniel Read</dc:creator>
 <guid isPermaLink="false">comment 1552 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Tried your WriteVariable function</title>
 <link>http://www.developerdotstar.com/community/node/512#comment-1551</link>
 <description>&lt;p&gt;Hey Dan,&lt;br /&gt;
It&#039;s wierd, I tried using your function with my script task editor and still the edited changes I made to the variable don&#039;t apply after the package is compiled.  &lt;/p&gt;
&lt;p&gt;Also when I run the package it stalls, when I edit the properties for script task editor, specifically  the &quot;ReadWriteVariables&quot; under script. So if I try to add in a variable under that heading, it doesn&#039;t successfully execute the script, but no error msg, just stalls.  Only executes when no variables are in the heading &quot;ReadWriteVariables&quot;   Has this happened to you?&lt;/p&gt;
&lt;p&gt;Thanks again,&lt;br /&gt;
Vince&lt;/p&gt;
</description>
 <pubDate>Tue, 03 Oct 2006 10:49:31 -0700</pubDate>
 <dc:creator>Vince</dc:creator>
 <guid isPermaLink="false">comment 1551 at http://www.developerdotstar.com/community</guid>
</item>
<item>
 <title>Reusable Functions for Reading and Writing Variables in SSIS Script Tasks</title>
 <link>http://www.developerdotstar.com/community/node/512</link>
 <description>&lt;p&gt;One of the first of many pains-in-the-butt that SQL Server Integration Services developers will encounter is how from a Script Task in the Control of Flow to write to and read from package variables. I have &lt;a href=&quot;http://www.developerdotstar.com/community/node/313&quot;&gt;blogged a bit about the topic of SSIS variables in script tasks&lt;/a&gt; in the past, but in this post I&#039;d like to share two custom functions that I copy and paste into all of my script tasks to simplify dealing with variables. If you use these functions you will not need the Script Task Edtior&#039;s ReadWriteVariables field to make your package variables available to the script.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.developerdotstar.com/community/node/512&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.developerdotstar.com/community/node/512#comment</comments>
 <category domain="http://www.developerdotstar.com/community/taxonomy/term/58">SSIS (SQL Server Integration Services)</category>
 <pubDate>Fri, 30 Jun 2006 08:26:05 -0700</pubDate>
 <dc:creator>Daniel Read</dc:creator>
 <guid isPermaLink="false">512 at http://www.developerdotstar.com/community</guid>
</item>
</channel>
</rss>
