Vous êtes sur la page 1sur 29

Master Child packages - Part 1: File based

Case
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

Solution
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.

A) File based
1) Variable
Add a string variable to the package and name it PackagePath. This will contain the filepath of the
package.

Right click in Control Flow

2) Foreach Loop
Add a foreach loop to your master package. Edit it to give it a suitable name and to select the File
Enumerator. If you need a certain order then you could install the Sorted File Enumerator.

File Enumerator

3) Path and folder


Enter the folder name where your packages are located and enter a filter (example: STG*.dtsx). Make
sure the Fully qualified options is selected.

Loop through package folder

4) Variable Mappings
Go to the variable mappings pane and select the variable from step 1. This will fill the variable with the
path of the current package.

Select the String variable from step 1

5) 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 (Location = File system). Just pick one. We will overrull the path in the
next step.

Calling a file based package

6) Expression
Go to the properties of your newly created File Connection Manager and add an expression on the
ConnectionString property that overrules its value with the variable PackagePath from step 1.

Expression on new connection manager

7) The result
A clear package with only one Execute Package Task and one Connection Manager.

Master Child packages - Part 2: SQL Server based

Case
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

Solution
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.

B) SQL Server based


For this solution, you need to create a query on the msdb database to get the list of packages from
Integration Service. For this query we need the system tables sysssispackages and
sysssispackagefolders.

Get list of packages from MSDB in SSIS 2008

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
MSDB.

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 MSDB

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

1
2
3
4
5
6
7
8

-- Get list of packages. Change the where clause.


SELECT '\' + folders.foldername + '\' + packages.name as PackagePath
--'Concatenate
FROM msdb.dbo.sysssispackages as packages
INNER JOIN msdb.dbo.sysssispackagefolders as folders
on folders.folderid = packages.folderid
WHERE folders.foldername = 'Staging'
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 (Location = SQL Server). Just pick one. We will overrull the path in the
next step.

Execute Package Task

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.

Master Child packages - Part 3: Project reference

Case
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

Solution
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

1
2
3
4
5
6

-- 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'

7
8

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.

Vous aimerez peut-être aussi