Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSIS 2012 pass values from child package to parent with project deployment model

Tags:

ssis

i'm using the new project deployment model.

I have a master package called ETL. The first thing my ETL package does is run a package called get SFTP files as shown.

enter image description here

Within Get SFTP files a foreach loop gets the ClientID. HOW do i pass this value back to the parent package ETL??? To do inserts etc.

enter image description here

like image 497
jhowe Avatar asked Nov 29 '13 15:11

jhowe


1 Answers

Here is a way to pass a value from a child package variable to a parent package variable.

Script Task: (in child package)

// Populate collection of variables.
// This will include parent package variables.
Variables vars = null;
Dts.VariableDispenser.GetVariables(ref vars);

// Lock the to and from variables. 
Dts.VariableDispenser.LockForWrite("User::MyParentPackageVar");
Dts.VariableDispenser.LockForRead("User::MyChildPackageVar");

// Apparently need to call GetVariables again after locking them.
// Not sure why - perhaps to get a clean post-lock set of values.
Dts.VariableDispenser.GetVariables(ref vars);
vars["User::MyParentPackageVar"].Value = vars["User::MyChildPackageVar"].Value;

vars.Unlock();

This code was actually from a pre-2012 SSIS Package that I just finished upgrading to SSIS for SQL Server 2012 (in Visual Studio 2012), and converted to project deployment model.

Initially, the execution died (after a lengthy delay) on the variable assignment line. But then I added the "User::" prefix, which apparently was necessary for at least one, but not all of the variables I was assigning this way. The prefix was not necessary in SSIS for SQL Server 2008.

like image 162
Zach Blocker Avatar answered Oct 16 '22 09:10

Zach Blocker