Frage

I'm running into an issue trying to pass data into a child package. My parent package runs through a db, checks it against another in order to run or not. Currently i'm using a ForEach Loop in order to do so. I then can identify the row i need to run by one unique id. Then i pass it to the appropriate child package to process it.

My question is, what's the easiest method of writing that identifier to a 4 byte variable so that it is available on a solution level, instead of package level. I can't pass anything through to the child package as far as i have seen either.

Thanks for assist! -D

War es hilfreich?

Lösung

Parameters are the thing you will be looking for in an SSIS 2012, Project Deployment Model, to allow you to pass data to the child package. In the child package, you will need to add a Parameter.

I created 5 packages: MasterPackage and ChildPackages_0 ... ChildPackage4

MasterPackage

enter image description here

MasterPackage has a 2 variables defined: "Variable" (Int32) and "ChildPackage". ChildPackage (String) has an expression applied "ChildPackage_" + (dt_wstr,1) @[User::Variable] + ".dtsx" As the value of Variable changes, so does this string.

Add a Foreach Loop (Item enumerator, goes from 0 to 4) and I map the current value to my poorly named variable "Variable."

I have an Execute Package Task defined that runs a package. In the Parameter Bindings tab, I mapped the child parameter named "Parameter" to the variable "User::Variable" I also applied an expression on the PackageName property to be the variable @[User::ChildPackage]. This results in the name of the package changing to reflect the value of the variable.

ChildPackage_X

In my child packages, I created a single parameter named "Parameter", assigned a default value of -1 and checked the Required attribute. The child package simply has a Script task that emits the value of the parameter. I added System::PackageName, $Package::Parameter to the list of Read Only parameters for that script. That code follows

public void Main()
{
    // System::PackageName, $Package::Parameter
    bool fireAgain = true;
    string myVariableName = "$Package::Parameter";
    int myVariableValue = -1;
    string packageName = Dts.Variables["System::PackageName"].Value.ToString();
    myVariableValue = (int)Dts.Variables[myVariableName].Value;

    Dts.Events.FireInformation(0, string.Format("{0} Script task", packageName), string.Format("{0}:{1}", myVariableName, myVariableValue), string.Empty, 0, ref fireAgain);

    Dts.TaskResult = (int)ScriptResults.Success;
}

Output

After running the master package, I received the following expected output. Each child package fired when it was their turn and the script task showed that the value was passed to them via their parameter as expected.

SSIS package "C:\sandbox\SO_SSIS\SO_SSIS\MasterPackage.dtsx" starting.
Executing ExecutePackageTask: C:\sandbox\SO_SSIS\SO_SSIS\ChildPackage_0.dtsx
Information: 0x0 at SCR Emit parameter, ChildPackage_0 Script task: $Package::Parameter:0
Executing ExecutePackageTask: C:\sandbox\SO_SSIS\SO_SSIS\ChildPackage_1.dtsx
Information: 0x0 at SCR Emit parameter, ChildPackage_1 Script task: $Package::Parameter:1
Executing ExecutePackageTask: C:\sandbox\SO_SSIS\SO_SSIS\ChildPackage_2.dtsx
Information: 0x0 at SCR Emit parameter, ChildPackage_2 Script task: $Package::Parameter:2
Executing ExecutePackageTask: C:\sandbox\SO_SSIS\SO_SSIS\ChildPackage_3.dtsx
Information: 0x0 at SCR Emit parameter, ChildPackage_3 Script task: $Package::Parameter:3
Executing ExecutePackageTask: C:\sandbox\SO_SSIS\SO_SSIS\ChildPackage_4.dtsx
Information: 0x0 at SCR Emit parameter, ChildPackage_4 Script task: $Package::Parameter:4
SSIS package "C:\sandbox\SO_SSIS\SO_SSIS\MasterPackage.dtsx" finished: Success.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top