Discounted Option
- The Set Variable Custom Task. It errors when referring to non local variables.
- Script Task in the Child Package (bleagh)
Public Sub Main()
Dim vars As Variables
'If package executed directly then no parent variables exist!
Try
Dts.VariableDispenser.LockForRead("ParentVar")
Dts.VariableDispenser.LockForWrite("ChildVar")
Dts.VariableDispenser.GetVariables(vars)
vars("ChildVar").Value = vars("ParentVar").Value
vars.Unlock()
Catch ex As Exception
'Do Nothing
Finally
Dts.TaskResult = Dts.Results.Success
End Try
End Sub
"The Parent Variable Write"
Public Sub Main()
Dim vars As Variables
'If package executed directly then no parent variables exist!
Try
Dts.VariableDispenser.LockForWrite("ParentVar")
Dts.VariableDispenser.LockForRead("ChildVar")
Dts.VariableDispenser.GetVariables(vars)
vars("ParentVar").Value = vars("ChildVar").Value
vars.Unlock()
Catch ex As Exception
'Do Nothing
Finally
Dts.TaskResult = Dts.Results.Success
End Try
End Sub
Notes
- No need for Parent Package Configurations if the child and parent variables are differently named
- There's no need to do anything in the Parent Package.
- Don't put anything in ReadVariables or ReadWriteVariables! This will cause additional LockForRead, LockForWrite and Unlock method calls.
- Set Parent Variable Custom Task
- Set Multiple Variables Custom Task
Hard to Template
If you want to go large with a deep package invocation hierarchy then it will be somewhat tiresome to code. This is because local variables override parent variables if they have the same name, so you can't use the same package template for all hierarchy levels.
e.g. if you have a package template with variables var1 and localvar1, create two packages from it and call one package from the other, the child package will use the local var1 and ignore the parent var1.
This is unfortunate because it's becoming steadily easier to work with templates in SSIS using tools such as Pacman.
No comments:
Post a Comment