Home > SSIS, SSIS programming > Programming Sequence Container

Programming Sequence Container

While building an ETL package, it’s very important to control the flow of work as per the requirement. And this can be done by using a SSIS component called Sequence container. The sequence container is a part of Control Flow and a sub part of the global container i.e. Control Flow container. Here we can set the flow of our package by precedence constraints.

The Sequence Container is basically used for grouping same type of tasks and to control them under a separate group. It can group the whole contents of the package into multiple separate control flows. The sequence container can be nested to any level to give more clarity to the process flow.

Here in this article, we will see the steps to control the tasks using Sequence container as well as how to do the same by programming Integration Services.

It comes with some additional plus points to control the components of the package like:

  • While debugging, one can disable or enable the whole set of tasks under a sequence container at a time.
  • One can set properties to all the tasks under a sequence container by simply setting the properties on the master sequence container.
  • Sequence container has its own scope, so the variables inside a sequence container have different scope than the variables outside.
  • It can be used along with Transaction property to have more granular control on the transaction done by the package. For example, if there are two tasks inside a sequence container, one task for withdrawing money from an account and another for depositing, then we can configure the sequence container to ensure that the task for withdrawing money will be rolled back if the task for depositing one fails.

Let’s have a simple example to see how the sequence containers are useful to guide the flow of the package. Here, our requirement is to get the information about the cars in separate tables categorized by fuel types. For details about the tasks used in this example, please refer to the earlier article “SSIS Programming Basic“.

The logic to implement the same and build the SSIS package is given below:

programmingsequencecont1

Here, we have two Execute SQL Tasks, one to log the starting information of the package and the other to log the package ending information. In between, we used a sequence container to hold the data flow tasks of both the categories. Each data flow task is surrounded by its sequence container. We can add any no. of tasks inside the sequence container and can guide the execution of these tasks by using precedence constraints. Here, both the data flow tasks will run parallel in order to increase the performance of the package.


Here the source table named “dbo.Car_Info” has the following data:

CarCompany

CarBodyType

CarName

EngineType

Maruti

small

Maruti-800

petrol

Maruti

small

Waganor Duo

petrol

Honda

sedan

City

petrol

TATA

small

indica

diesel

Mahindra

SUV

Scorpio

diesel

TATA

SUV

Sumo

diesel

Maruti

sedan

SX4

petrol

Maruti

sedan

Swift-Dzire

diesel

TATA

small

Nano

petrol

And after executing the above package, our destination tables have the following data:

Table: dbo.DieselCars

CarCompany

CarBodyType

CarName

EngineType

TATA

small

indica

diesel

Mahindra

SUV

Scorpio

diesel

TATA

SUV

Sumo

diesel

Maruti

sedan

Swift-Dzire

diesel

Table: dbo.PetrolCars

CarCompany

CarBodyType

CarName

EngineType

Maruti

small

Maruti-800

petrol

Maruti

small

Waganor Duo

petrol

Honda

sedan

City

petrol

Maruti

sedan

SX4

petrol

TATA

small

Nano

petrol

So we successfully separated the information about the cars as per the fuel type. Let’s do the same in Integration programming. The code below is done in both C# .net and VB .net as well as in both the versions of SSIS i.e. SQL Server 2005 and SQL Server 2008.

Here, we have to create the package first, followed by creation of tasks for start and end indicator of the package. And then the sequence containers have to be created as per the logic where the data flow tasks are embedded. The logic to extract data separately is given inside the data flow tasks itself.

The creation name for Sequence container is “STOCK:SEQUENCE” (Both for SQL Server 2005 and SQL Server 2008).

Note: For detail about the other components of the package, please refer to the earlier post named “SSIS Programming Basic“.

The code below shows the above package programmatically and the code itself is self-descriptive. The code for SQL server 2005 and SQL Server 2008 are a bit different; both the approaches are given below.

Add the below References before developing the code.

Microsoft.SqlServer.Dts.Design
Microsoft.SqlServer.DTSPipelineWrap
Microsoft.SQLServer.DTSRuntimeWrap
Microsoft.SQLServer.ManagedDTS

Programming Integration Service in SQL Server 2005

Expand image C# .Net Expand
Expand image VB .Net Expand

Programming Integration Service in SQL Server 2008

Expand image C# .Net Expand
Expand image VB .Net Expand

To make your work more easy and effortless, SQL Lion team comes up with a unique tool named “SSIS Component Explorer” that will help you in retrieving the Creation Name, Component Class ID, etc about any component like Control Flow Tasks, Data Flow Transformations, Connections Managers, Log Providers, etc in SSIS package. It also provides code snippets for each component.
Download
the free version from here.


References:
MSDN Books Online

Categories: SSIS, SSIS programming
  1. No comments yet.
  1. No trackbacks yet.