BIML - Passing Variables to Child Packages
A project I’ve been working on recently has consisted of lots of little packages which are called from a single coordinating package. I started off developing against SQL Server 2012, and thankfully used BIML to generate all my packages. The main controller package passes a variable down to the sub-packages, which is then subsequently used when executing a stored proc. This all worked nicely until I was told that it needed to work against SQL Server 2008 :-( Thanks to the ease with which BIML allows changes to be made I had it fixed and working again within minutes.
This post will show how to pass variables from a parent package to a child package for both SQL Server 2012 and SQL Server 2008.
SQL Server 2012
This is actually really easy for SQL Server 2012, thanks to the introduction of package parameters. The below BIML will generate two SSIS packages.
Parent - This package has a variable defined as ParentVar, the Execute Package data flow task will pass this variable as the value for the ChildVar parameter defined in the Child package.
Child - This package has a single parameter defined, ChildVar which will have the value filled in by the Parent package.
|
|
SQL Server 2008
In SQL Server 2008 we don’t have the luxury of package parameters so we have to fall back to Package Configurations. To pass a variable to a child package we need to define a “Parent package variable” configuration, which tells the Child package to expect a given variable from the Parent package and which local variable it should be mapped to.
Once again the following BIML will generate two packages.
Parent - This package has the variable defined and set, as well as an Execute Package data flow task which will execute the Child package
Child - This package has a Package configuration which will map the ParentVar variable to the local ChildVar variable. You can see the Package Configurations by right clicking anywhere in the package control flow and then clicking Package Configurations, this will bring up the following:
|
|
(To use this sample, make sure that the project you generate the packages in is set to the “Package Deployment Model”)
🍪 I use Disqus for comments
Because Disqus requires cookies this site doesn't automatically load comments.
I don't mind about cookies - Show me the comments from now on (and set a cookie to remember my preference)