Saturday 12 September 2020

SSIS Pass Variable from Parent to Child Package Using a Script Task

In this demo, we will see how we pass the parent package variable to the child package using a script task. We will create a variable in the parent package, assign a value and use this variable in the child package using a Script Task.

Let’s see

We have two package

Ø  Call_Child_Package.dtsx (Parent package)

Ø  Child.dtsx (Child Package)

In the parent package, we are creating a variable. 

Now In the child package, we are creating a variable to assign the parent package variable. 

Keeping the default value as blank.

In the child package, we are taking the script task.  

Double click on the script task.  


In the ReadOnlyVariable we are passing the Parent package variable and ReadWriteVariable we are passing the child_variable.

In the script task we are writing the below code.

public void Main()

                                {

            // TODO: Add your code here

            Dts.Variables["Child_Variable"].Value = Dts.Variables["Parent_Variable"].Value;

            MessageBox.Show(Dts.Variables["Child_Variable"].Value.ToString());

            Dts.TaskResult = (int)ScriptResults.Success;

                                }

Same and close the script task.

Now in the parent package, we are taking the execute package task and selecting the reference type as a project reference.

Selecting the child package. 

Click ok.

Now the parent package is ready to run.     

Now we are executing this package.   

A variable which is assigned in the parent package we are calling it in the child package.

Execute package task is completed successfully.  

Hope this will help to use the parent package variable in the child package.

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts