Wednesday, April 16, 2008

SSIS: Read/Write Package Variables Inside Script Task

To pull a SSIS Package variable into the Script Task you're working on use this


Dim vars As Variables
Dts.VariableDispenser.LockOneForRead("User::VariableName", vars)

Dim variable As String = vars("VariableName").Value.ToString()

vars.Unlock()


and then use your variable as you need.

To write to a SSIS Package variable in a Script task that you're working on, so future tasks in the package can use it, use the following


Dim writeVars As Variables
Dts.VariableDispenser.LockOneForWrite("User::VariableName", writeVars)
writeVars(0).Value = "Hello World"

writeVars.Unlock()


If you're using a variable to hold a value established in a Script task for use in further tasks, make sure its scope is not limited to just the script task we've made here.