Tuesday, 1 January 2013

Master Child packages - Part 3: Project reference

An often seen solution is a master package calling a couple of child packages with the Execute Package Task. This works fine for a couple of packages, , but is a little boring for a whole bunch of packages. Is there an easier more clear way to maintain a master package?
Server based and file based child packages

A simple solution is to use a Foreach Loop Container with an Execute Package Task in it that loops through a folder with packages. It works both for file-based and server-based packages.

But there are a couple of drawbacks:
Drawback 1: The child packages are not executed simultaneously, but one after another. Will handle this problem in a future post.
Drawback 2: The options to determine the order of execution are limited. You can only order by name. So if a certain order is required then you need to add some prefix to the packagename to determine the order.

I have prepared three solutions:
A) File based: SSIS 2005, 2008 or 2012 if you use package deployment.
B) SQL Server based: SSIS 2005, 2008 or 2012 if you use package deployment.
C) Project Referenced: SSIS 2012 if you use project deployment. This solution is nearly equal to solution B.

C) Project Referenced
For this solution, you need to create a query on the SSISDB database to get the list of packages from Integration Service. For this query we need the tables internal.packages and internal.projects.
Get list of packages from SSISDB in SSIS 2012

1) Variables
Add a string variable to the package and name it PackagePath. This will contain the filepath of the package. Also create an object variable named Packages. This will contain a list of packages from the SSISDB.
Right click in Control Flow

2) OLE DB Connection Manager
Create an OLE DB Connection Manger that connects to the msdb database. We will use this connection manager for geting a list of packages and to execute the SQL Server based packages.
OLE DB Connection to SSISDB

3) Execute SQL Task
Add an Execute SQL Task and give it a suitable name. Edit it; Set ResultSet to Full result set. Select the newly created Connection Manger and enter the query below.
Execute SQL Task

-- Get list of packages. Change the where clause.
SELECT      Packages.[name]
FROM        [SSISDB].[internal].[packages] as Packages
INNER JOIN  [SSISDB].[internal].[projects] as Projects
            on Packages.project_version_lsn = Projects.object_version_lsn
WHERE       Projects.name = 'MasterChildPackages'
AND         Packages.name like 'STG%'
ORDER BY    Packages.name

4) Execute SQL Task - Result Set
Go to the Result Set pane and click Add and select the object variable from step 1. The Result Name should be 0.
Result Set

5) Foreach Loop
Add a Foreach Loop Container to the control flow and give it a suitable name. Then connect the Execute SQL Task to the Foreach Loop.
Foreach Loop Container

6) Foreach ADO Enumerator
Edit the Foreach loop and select the Foreach ADO Enumerator as the enumerator type. After that select the object variable Packages as the ADO object source variable. The Enumeration mode should be "Rows in the first table".
Foreach ADO Enumerator

7) Variable Mapping
Go to the Variable Mapping pane and select the PackagePath variable for index 0.
Variable Mappings

8) Execute Package Task
Add an Execute Package Task in the Foreach Loop. Give it a suitable name and configure it to call one of your child packages (ReferenceType = Project Reference). Just pick one. We will overrull the path in the next step.
Execute Package Task - Project Reference

9) Expression
Go to the properties of your newly created Execute Package Task and add an expression on the PackageName property that overrules its value with the variable PackagePath from step 1.
Expression overrulling PackageName(path)

10) Delay Validation
If the value of the PackagePath variable doesn't contain a real path of a variable, then you will get a validation error on runtime. You could either fill the variable with a default value or just set the Delay Validation property of the Execute Package Task to false.
The package is not specified

11) The result
A clear package with only one Execute Package Task.
The result

Go to A) File based or B) SQL Server based

No comments:

Post a Comment

Please use the SSIS MSDN forum for general SSIS questions that are not about this post. I'm a regular reader of that forum and will gladly answer those questions over there.

All comments are moderated manually to prevent spam.

Related Posts Plugin for WordPress, Blogger...