Professional Documents
Culture Documents
LAB04-Implementing Control Flow in An SSIS Package
LAB04-Implementing Control Flow in An SSIS Package
TAKE AWARE : Text which is writen in red color should be personalized with your personal parameters.
Objectives
After completing this lab, you will be able to:
• Use tasks and precedence constraints.
• Use variables and parameters.
• Use containers.
Scenario
You have implemented data flows to extract data and load it into a staging database as part of the ETL process
for your data warehousing solution. Now you want to coordinate these data flows by implementing a control
flow that notifies an operator of the outcome of the process.
The main tasks for this exercise are as follows:
1. Prepare the Lab Environment
2. View a Control Flow
3. Add Tasks to a Control Flow
4. Test the Control Flow
N.B. To well complete the following tasks we suppose that you have a local SMTP server for managing
emails. If you don’t have it in your personal machine, questions in blue color will not function. This is not
a problem since the goal of this exercise is to well known how to implement the process of sending mail in
case of loading data errors.
1. In Visual Studio, in Solution Explorer, in the SSIS Packages folder, double-click Extract Internet Sales
Data.dtsx. Then view the control flow for the Extract Internet Sales Data package.
2. In the SSIS Toolbox, in the Common section, double-click Send Mail Task. Then position the new
Send Mail task below and to the right of the Extract Internet Sales task.
3. Double-click the Send Mail task on the control flow surface, to view its settings, and in the Send
Mail Task Editor dialog box, on the General tab, set the Name property to Send Success
Notification.
4. In the Send Mail Task Editor dialog box, on the Mail tab, in the SmtpConnection drop-down list,
click <New connection>. Then in the SMTP Connection Manager Editor dialog box, enter the
following settings and click OK:
• Name: Local SMTP Server
• SMTP Server: localhost
5. In the Send Mail Task Editor dialog box, on the Mail tab, enter the following settings, and then click
OK:
• From: ETL@adventureworks.msft
• To: Student@adventureworks.msft
• Subject: Data Extraction Notification
• MessageSourceType: Direct Input
• MessageSource: The Internet Sales data was successfully extracted
• Priority: Normal
6. On the Control Flow surface, click the Extract Internet Sales task, and then drag the green arrow
from the Extract Internet Sales task to the Send Success Notification task.
7. In the SSIS Toolbox, in the Common section, double-click Send Mail Task. Then position the new
Send Mail task below and to the left of the Extract Internet Sales task.
8. Double-click the Send Mail task on the control flow surface, to view its settings, and in the Send
Mail Task Editor dialog box, on the General tab, set the Name property to Send Failure
Notification.
9. In the Send Mail Task Editor dialog box, on the Mail tab, enter the following settings, and then click
OK:
• SmtpConnection: Local SMTP Server
• From: ETL@adventureworks.msft
• To: Student@adventureworks.msft
• Subject: Data Extraction Notification
• MessageSourceType: Direct Input
• MessageSource: The Internet Sales data extraction process failed
• Priority: High
10. On the Control Flow surface, click the Extract Customers task, and then drag the green arrow from
the Extract Customers task to the Send Failure Notification task. Then right-click the arrow and
click Failure.
11. On the Control Flow surface, click the Extract Internet Sales task, and then drag the green arrow
from the Extract Internet Sales task to the Send Failure Notification task. Then right-click the arrow
and click Failure.
12. Double-click the red arrow connecting the Extract Customers task to the Send Failure Notification
task. In the Precedence Constraint Editor, in the Multiple Constraints section, select Logical OR.
One constraint must evaluate to True. Then click OK.
Results: After this exercise, you should have a control flow that sends an email message if the Extract Internet
Sales task succeeds, or sends an email message if either the Extract Customers or Extract Internet Sales
tasks fail.
Scenario
You need to enhance your ETL solution to include the staging of payments data that is generated in comma-
separated value (CSV) format from a financial accounts system. You have implemented a simple data flow that
reads data from a CSV file and loads it into the staging database. You must now modify the package to
construct the folder path and file name for the CSV file dynamically at run time instead of relying on a hard-
coded name in the data flow task settings.
The main tasks for this exercise are as follows:
1. View a Control Flow
2. Create a Variable
3. Create a Parameter
4. Use a Variable and a Parameter in an Expression
Note that the value includes a space on either side of the “-“ character.
3. On the File menu, click Save All, and then close the Project.params [Design] window.
Results: After this exercise, you should have a package that loads data from a text file based on a parameter
that specifies the folder path where the file is stored, and a variable that specifies the file name.
Scenario
You have created a control flow that loads Internet sales data and sends a notification email message to
indicate whether the process succeeded or failed. You now want to encapsulate the data flow tasks for this
control flow in a sequence container so you can manage them as a single unit.
You have also successfully created a package that loads payments data from a single CSV file based on a
dynamically-derived folder path and file name. Now you must extend this solution to iterate through all the
files in the folder and import data from each one.
The main tasks for this exercise are as follows:
1. Add a Sequence Container to a Control Flow
2. Add a Foreach Loop Container to a Control Flow
Results: After this exercise, you should have one package that encapsulates two data flow tasks in a sequence
container, and another that uses a Foreach Loop to iterate through the files in a folder specified in a parameter
and uses a data flow task to load their contents into a database.
Part 2 : Using Transactions and Checkpoints
Scenario
You are concerned that the Adventure Works ETL data flow might fail, leaving you with a partially-loaded
staging database. To avoid this, you intend to use transactions and checkpoints to ensure data integrity.
Objectives
After completing this lab, you will be able to :
• Use transactions.
• Use checkpoints.
Scenario
You have created an SSIS package that uses two data flows to extract, transform, and load Internet sales data.
You now want to ensure that package execution always results in a consistent data state, so that if any of the
data flows fail, no data is loaded.
The main tasks for this exercise are as follows:
1. Prepare the Lab Environment
2. View the Data in the Database
3. Run a Package to Extract Data
4. Implement a Transaction
5. Observe Transaction Behavior
1. Start SQL Server Management Studio and connect to the (local) instance of the SQL Server database
engine by using Windows authentication.
2. Restore files all files in the « LABS-Atelier SID\Lab04\LabB\BackupFiles » folder. You should delete
existant databases before starting restoring newest ones. Indication : Refer to « Préparation
Environnement Labxx » file in the « LABS-Atelier SID » folder for help.
3. Execute the « Update Environment.sql » file in the « LABS-Atelier SID\Lab04\LabB\BackupFiles »
folder
1. Start SQL Server Management Studio, and when prompted, connect to the localhost database
engine using Windows authentication.
2. In Object Explorer, expand Databases, Staging, and Tables.
3. Right-click dbo.Customers and click Select Top 1000 Rows. Note that the table is empty.
4. Right-click dbo.InternetSales and click Select Top 1000 Rows. Note that the table is also empty.
5. Minimize SQL Server Management Studio.
Results: After this exercise, you should have a package that uses a transaction to ensure that all data flow
tasks succeed or fail as an atomic unit of work.
Exercise 2 : Using Checkpoints
Scenario
You have created an SSIS package that uses two data flows to extract, transform, and load reseller sales data.
You now want to ensure that if any task in the package fails, it can be restarted without re-executing the tasks
that had previously succeeded.
The main tasks for this exercise are as follows:
1. View the Data in the Database
2. Run a Package to Extract Data
3. Implement Checkpoints
4. Observe Checkpoint Behavior
Results: After this exercise, you should have a package that uses checkpoints to enable execution to be
restarted at the point of failure on the previous execution.