In this article we will understand how we can use a Sequence Container with a demo. In my previous article I wrote about Control Flow Objects in SSIS.
Sequence Container and its benefits
Sequence container groups related tasks in a package and helps in understanding the complexity of a package in a simpler way. The objective of the Sequence container is to have multiple separate control flows grouped together in the package.
Some of the benefits of the package are as below:
1) Helps in debugging.
2) If a package has multiple tasks then it is easier to group the tasks in Sequence Containers and we can collapse and expand this container for usability.
3) We can set the property of entire container rather than setting the property of individual tasks.
4) We can set the flexibility of completion of the process in the container to a transaction level i.e in case of an error the entire process can be rolled back or partial success can be achieved.
Implementing Sequence Container
Now we will implement the sequence container with a demo. In the first example we will not use TransactionOption but in the second example we will. Let us begin. We will be using the project we created in my article.
Step 1: Open the SSIS Project -> Click on the package MyPackage.dtsx -> Drag and drop a Sequence Container from the toolbox on the design surface -> Drag three Execute SQL Task objects in the Sequence ContainerStep 2: Rename the 1st Task as Create Table. Rename the second task as Insert Values. Rename the 3rd Task as Update Values -> Drag the constraint from the 1st task onto the Insert Values Task and then drag the constraint from the Insert Values Task onto the Update Values Task. The structure should look like below
Step 3: Right click on the Create Table Task -> Click Edit -> Change the connection to AdventureWorks2008 -> Click on the SQLStatement and insert the following code -> Click on OK.
CREATE TABLE [SequenceContain] ( id INT NOT NULL, NAME VARCHAR(20), age INT )
Step 4: Implement the same for Insert Values Task apart from the SQL. Insert the below SQL code
INSERT INTO dbo.SequenceContain VALUES (1,'Amit A',34),(2,'Amit B',34), (3,'Amit C',24),(4,'Amit D',44), (5,'Amit E',64),(6,'Amit F',34)
UPDATE SequenceContain SET name = 'Bodhi' WHERE id = 3
Step 5: Press F5 and the package execution begins. The entire package will turn green when the execution succeeds
Step 6: Lets verify via SQL Server if the table and data has been created and modified.
Now lets tweak the third task i.e Update Values task and enforce an error. We will change the TransactionOption to NotSupported.
Step 1: Right click on the Update Task -> Goto SQLStatement -> insert the following code below
UPDATE SequenceContai SET name = 'Bodhi' WHERE id = 3
We have kept the name of the table incorrect to enforce the error.
Step 2: Select the Sequence Container -> On the properties tab -> TransactionOption -> Select Not Supported.
Step 3: Not lets drop the table from the database so that the create table does not error out.
Step 4: Press F5 and run the package and lets observe what happens
Observation: What we observe is that the package has failed(red) and the update values Task has also failed(red). Let now have a look at the database and see what impact has this package made.
What we observe is that create table and insert values task has succeeded but the update values task has failed. So this what NotSupported does. It does not do a full roll back.
Now we will change the TransactionOption to Required and observe what happens
Step 1 : Drop the table from the database
Step 2 : Change the TransactionOption to Required
Step 3: Press F5.
The Package fails but lets verify what has happened at the database level by running a select on the table.
The entire process has been rolled back. The table structure does not exist even though the create table had succeeded. So this is what The Required option does. In case of an error it rolls back the entire package.
In this article I have tried to explain the use of the sequence container in a simplified manner. I hope i was able to do that.