I have become accustom to modifying package variables within myScript Task using theVariablesDispenser object. It is convenient and powerful. I started working with this object due to issues I found while hacking my way through SSIS2005. I would put the variables in the ReadOnly or ReadWrite section and would get weird errors attributed to exclusive locking..blah,blah,blah. I naturally carried this practice over to SSIS2008 and things work the same; in theScript Task.

Getting heavily involved in SSIS development I broke down and decided to do moreScript Component work. Prior to SSIS I had done my absolute best to keep away from VB.Net and along with that,Script Components. I just didn't like the way VB 'felt'. To be honest, there is nothing wrong with choosing or avoiding a language based upon personal preference, so long as the language chosen is proper for the job. Seeing C# as an option in SSIS2008, I decided that would be my language of choice and was once again excited about getting intoScriptComponents to begin developing again.

My first foray back into programmingScript Components, I had a hard time using theVariablesDispenser in theScript Component. I couldn't find theVariables object. Thinking there had to be an easier way, I went back to using theReadOnly/ReadWrite Variables property. This wasn't much easier. Turns out, these variables can only be accessed within certain sections of your Script Component. ReadWrite variables are available through theVariables object in thePostExecute() method only:

ReadOnly variables are only available to theVariables object in thePreExecute() method. I also found some interesting bugs regarding this (see previous postscript gotchas). This worked fine for me, but being more stubborn than smart, I wanted to figure out a way to access these variables the way I was most comfortable, using theVariablesDispenser. A few sleepless nights later I found what I was looking for; IDTSVariables100object.

You no longer access theVariableDispenser object through Dts and you no longer pass in the a variable of typeVariables. Instead you access the package level variables directly throughVariableDispenser and pass all of the locked package variables into a local variable of typeIDTSVariables100.

"So what does this buy me?". First, I am not constrained to have myReadOnly variables accessible only in thePreExecute() method and myReadWritevariables accessible only in thePostExecute() method. This means I don't need local variables to pass information around or keep counts of things to later push out. This is really only useful inScript SourceandScript Destination objects where you don't loop through the methods for each row. It's also easier to copy/past the code in the above example to move to it multiple scripts vs having to hand code each script'sReadOnly/ReadWrite section. Last, but not least; personal preference.