Parameter bindings in ssis - ssis

How to dynamically pass value to the child package variable by using Execute Package Task?
I need to call a package(child) from another package (parent) concurrently. In every call, I require to pass different value to child package variable
I have tried using parameter bindings in Execute Package Task but, some where I made mistake. Its not passing value as expected. Passing only empty
Eg:
one parent and one child. 3 different tasks to run same child. I want to pass 3 different variables from parent to a single child variable
Thanks in advance

To pass a variable from a parent package to a child package, you can use Package Configurations.
In your parent package, create the variable you want to pass the value from. Let's call it varParent. Now, use an Execute Package Task to reference the child package. You don't need any parameter bindings.
In your child package, create the variable that will receive the value from the parent package - varChild. Right click on an empty space in the Control Flow and select Properties. Scroll to Configurations under Misc. and click the button with the three dots.
Check "Enable package configurations" and click Add. The Package Configuration Wizard opens. Click Next.
In Configuration type, select Parent package variable. In the Parent variable field, enter varParent. Click Next.
In the tree view folder structure that shows, expand Variables, varChild, Properties and select Value. Click Next.
Give your Configuration a name and click Finish. Close the Package Configurations Organizer.
Now, you varChild will get the value from varParent.

Related

SSIS Execute Package task notification if path does not exist

I have created a master control package that calls several packages using the execute package task control. I have set all the package file locations to use a sql config table which contains the file location and then used an expression to include the package name. Everything works as expected however I want to include some handlers to notify me if the package location does not exist (just in case somebody changes the path in the config table). To test I set an incorrect file name in one of the expressions which turned the execute package task control red as expected however I can't figure out how to add the notification task. I have tried all the error handler events assocaited with it but no joy plus I added a mail task to the task in question for failure and this did not execute!
Any advice greatly appreciated.
Thanks.
That's why you have OnError event handler, just configure it properly. Are you sure, you're checking Event Handlers for the package and not for one of the blocks inside?
There's a plenty of system variables with OnError scope. Check grey x in Variable window to see them. You might want to use:
- ErrorDescription
- ErrorCode
- SourceName
but choose them according to the report format.
Now in event handler create a script which will put a message into a new variable, and finally send it with send mail task.

SSIS Script Task: How do I set a variable in one package and use it in another

I need to use a variable I get in a Script Task in one package in a Script Task in another package. How can I make a variable with a scope that spans packages? Are there Project variables?
Prior to SQL Server Integration Services 2012, the only way to share a value between packages was to use Parent/Child configuration. You could actually share a value between them without using configurations but it was janky as all get out.
If you have no need of bi-directional communication, then you could have package A (one that computes the value in script task) start package B and use the /SET properties to assign a value to the variable
dtexec /file PackageB.dtsx /Set \Package.Variables[User::SharedVariable].Properties[Value];\"I was computed\"
In a SQL Server 2012 project deployment model, the Configuration concept has been replaced with Parameters. This is a bit more straight forward as you define Parameters and specify whether they are required. The Execute Package Task provides a nice mapping mechanism between local variables and expected Parameters.
In SSIS 2005 and 2008:
Declare a variable - say p as int - at the package level
Call your child package from the parent package.
Now, if you have a script task in the Child package, you can access the variable p like this:
1. Pass ReadOnly variable p in the Script Task Editor of Child package
2. To access the parent variable: Dts.Variables["p"].Value;
Notice, that I have not use "User::p" in any of the above two steps. I find this method straight-forward.
Make sure you do not declare a variable p at the child package level.
So, how does this method work? Think of the basic concept of the scope of a variable. The script task will keep "going up" to find the variable p. Going up means - it will first try to find it at task level, then container level, then package level, then finally at parent package level. (This is a simple explanation - technically each of these levels are containers.)
In SSIS 2012, you can also use parameters to pass the variable in ReadOnly mode. The method described above can also be used in SSIS 2012 with added advantage of being able to overwrite the value of the parent variable.

How can I access a variable across script tasks within a package?

I have got two SSIS script tasks within a Sequence Container. I have declared variable StartTime in Script Task 1. I want to use this variable in Script Task 2.
Is it possible to access the variable StartTime within Script Task 2? How can I access the variable?
When you create variables in SSIS packages, you can define the scope of the variable. This scope defines which tasks on the Control Flow have visibility to the variables.
Sample package describing variable scopes:
Here is a sample SSIS package.
I have created a package with a sequence container and two Script Tasks within it. I have created four variables under different scope.
If you want to view all the variables defined under different scopes, you need to check the fourth button on the Variables pane. The option is indicated by the arrow in the screenshot.
Here is how the variables work in each of these scope:
StartTime_Package - This variable is declared under the scope MyPackage, which also happens to be the package name. This is the top level scope. This variable will be visible to all the tasks on the Control Flow.
StartTime_Sequence - This variable is declared under the scope Sequence Container, which is the given name of the sequence container task. This variable will be visible only to the Sequence container and the tasks within the sequence container.
StartTime_Task1 - This variable is declared under the scope Script Task 1, which is the given name of the first script task within the sequence container. This variable will be visible only to the first script task and no other tasks.
StartTime_Task2 - This variable is declared under the scope Script Task 2, which is the given name of the second script task within the sequence container. This variable will be visible only to the second script task and no other tasks.
How can I check if a task can access a variable or not?
Here is an easier way to identify if a particular task can access a variable or not. Let's uncheck the third option on the Variables pane.
Click on the Script Task 1. You will notice that the variable StartTime_Task2 is not displayed on the Variables pane because Script Task 1 does not have visibility to it.
Likewise, you can click on the task and verify which variables it can access.
You have to decide what the scope of the variable should be based on your requirements. If you are going to share the value of a variable across tasks, it is safe to declare it at the topmost package level scope.
If you are very sure that you will not access a certain variable outside of a particular task, it is safe to declare it at that task's scope level.
How to read a variable or write a value to variable using Script Task?
Double-click on the Script task, it will bring the Script Task Editor. You have to determine whether you just want to read the variable values or modify it within the task. I am going to modify a variable value and then display the value in a message box. To do that, I have to pick a variable that is already declared on the package and provide the script task the read and write access. Click the Ellipsis button against the ReadWriteVariables property
Select Variables will list the variables (both system and user level) to which the script task has access to. I am going to pick StartTime_Package variable.
You can see the variable now listed in the property. You can select multiple variables to. Click Edit Script so we can modify the C# code to write a value to the variable and then read it.
Paste the following code into the Script Task. First line assigns the value, here I am just adding 7 days to today's date. Second line displays the value of the variable in a message box.
public void Main()
{
Dts.Variables["StartTime_Package"].Value = DateTime.Now.AddDays(7);
MessageBox.Show(Dts.Variables["StartTime_Package"].Value.ToString());
Dts.TaskResult = (int)ScriptResults.Success;
}
If we run the package, it will display the value in message box. The package was executed on November 1, 2012 and you can that the package is displaying the modified value of November 8, 2012.
Hope that gives you an idea about variables scope within SSIS.
Make sure the scope of the variable (StartTime) is Package - that should do. Variable is available for use across the package.
In the first script task, add your variable as a Readwrite variable and maybe assign some value in the script.
In the second script task also, add it as a read or readwrite variable and you can reference it there.

Resume Parent package even Child Package fails

I am using Execute Package Task in my job to call my child Packages. I use an execute SQL Task to get my file location and file name to load the file into my tables.
Once I get these details I'll pass this information to my Execute Package task, where upon it calls my child Package.
My query triggers 2 input files, which has to be loaded into my tables.
For example, let us assume file1.csv and file2.csv has to be loaded. So when file1.csv is loading, if there is any error in my child package, my child package fails and my parent package does too. It should not happen like that; if my file1.csv fails to load, my child package and parent package should not fail and should continue loading file2.csv.
For this I tried changing the Propagate System variable value to false for execute Package task for On Error Event, still I couldn't solve the problem.
You can
Handling the error by setting up a failure path after the task that possibly fails
Set the MaximumErrorCount to a higher value (click into the background of your control view and go to properties)

Invisible component in SSIS Dataflow package

Everytime I run my data flow component, it gives me a validation error on a component whose name I cannot find in the editor! I think it happpened when I did ctrl-c on an existing component, and did ctrl-v. and it was successfully pasted, but somehow I can't see it, and therefore can't remove it!. My package is damaged as a result. Any ideas?
Can you see it in the XML when you select View..Code in Visual Studio? Or can you select it from the object drop down list in the Properties window?