June 20, 2008 at 5:56 am
Can a child package change the value of variables in the parent package? If not, what is a good way to pass values back to the parent?
I am developing a large application where most of the activity will occur in several child packages and a parent package will run them in sequence. Changing the value of a variable in the parent will make the new value available for the rest of the children.
June 20, 2008 at 8:55 am
I'm not sure, but my initial thought is no.
However, the easiest way to get it done is to have the child save the new value to a table and just have the parent read that table and assign the var to the result. Now you're always up to date.
Watch my free SQL Server Tutorials at:
http://MidnightDBA.com
Blog Author of:
DBA Rant – http://www.MidnightDBA.com/DBARant
June 22, 2008 at 8:16 pm
Thanks! I finally got a chance to experiment Friday afternoon at work. It looks like it is possible if you let the child reach into the parent for variables. But I ran into other problems with this approach. Your idea of the table sounds safer.
June 23, 2008 at 5:55 am
crever is correct that one option would be to use a SQL table to communicate between parent and child packages.
You can also use Package Configurations to pass data from parent to child and back again. There is a configuration type called "Parent Package Variable" which will require you to enter the Parent Package variable name prefixed with User:: or System:: depending on the type of variable you are retrieving. You can then update the variable value in the child package and it will be returned to the parent.
June 23, 2008 at 4:14 pm
Thanks!
June 27, 2008 at 5:00 am
Another option is to use the raw data file.
This acts just like a staging area as with the first suggestion but has the advantage of not requiring creation of a physical table.
It depends upon your exact requirements though the Package Configs for Parent variables is your best option depending upon the amount of data.
Paul R Williams.
June 27, 2008 at 8:41 am
Thanks! The amount of data that needs to be passed is small in this case. But this gives me 3 different approaches depending on the situation.
July 8, 2008 at 6:03 pm
Here is a way for a child package to change variables in the parent package.
In the child package,
1. Define the variables that you need. But DO NOT INCLUDE the ones that you want to update in the parent. If you need a variable for them, give it a different name.
2. Define a package configuration for each variable whose value you want from the parent. DO NOT INCLUDE the ones you want to update. If you need them, then map them to a different name.
3. To easily reference and update variables, please see Daniel Read's blog. (http://www.developerdotstar.com/community/node/512/)
I learned from his blog that it is better to use the variable dispenser than the readonly and readwrite sections of the script task or component. Otherwise, the variables tend to be locked too long, increasing the risk of a deadlock if you have multiple threads running.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply