Tuesday 11 December 2012

Sequence Container in SSIS 2008


The Sequence Container defines a control flow that is a subset of the control flow in a package. Sequence containers group the package into multiple separate control flows, each containing one or more tasks and containers that run within the overall package control flow. There are some benefits of using a Sequence container which are mentioned below:
  • Provides the facility of disabling groups of tasks to focus debugging on one subset of the package control flow.
  • Managing multiple tasks in one location by setting properties on a Sequence Container instead of setting properties on the individual tasks.
  • Provides scope for variables that a group of related tasks and containers use.

If a package has many tasks then it is easier to group the tasks in Sequence Containers and you can collapse and expand Sequence Containers.
Note: You can also create task groups which collapse and expand using the Group box this is a design-time feature that has no properties or run-time behavior.

Now I'll explain you how to use sequence Container in a package.
  1. To begin, right click on SSIS Packages folder in Solution Explorer and click New SSIS Package. Rename it with SequenceContainer.dtsx as shown below:


  2. Add a package variable DayOfWeek


  3. Drag and drop Script Task from toolbox. This task will be used to initialize DayOfWeek variable with current day of week. Rename Task name as Script Task - Set DayOfWeek.

  4. Double click on Script Task to open Script Task Editor. Enter User::DayOfWeek in ReadWriteVariables property.


  5. Click on Edit Script... and write below code in Main() function of ScriptMain.cs:


  6. Drag and Drop 7 Sequence Container tasks from Toolbox and rename the task on Week Days e.g. "SC - Sunday", "SC - Monday" etc. I am not placing any controls flow items inside Sequence Container to narrow down the example and focus more on how to use sequence container.

  7. Connect all these Sequence Containers to Script Task. Now double click on green arrow to open Precedence Constraint Editor. Select Evaluation operator as Expression and Constraint and Expression as @DayOfWeek == "Sunday". Click OK to close and save changes. The Expression for remaining task will be differ as per week day e.g. @DayOfWeek == "Monday" for Monday and so on.


  8. Save the package. Now right click on the package in Solution Explorer and execute the package.


  9. This package will execute only one sequence container as per expression set for the precedence constraints.


  10. This is just an example of how we can use Sequence Container. But we can use this in many ways which depends on the requirement.

No comments:

Post a Comment