Master Child Packages

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

description

Master Child

Transcript of Master Child Packages

Page 1: Master Child Packages

Master Child packages - Part 1: File basedCaseAn 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

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

Page 2: Master Child 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 based1) VariableAdd 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 LoopAdd 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.

Page 3: Master Child Packages

File Enumerator

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

Page 4: Master Child Packages

Loop through package folder

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

Page 5: Master Child Packages

Select the String variable from step 1

5) Execute Package TaskAdd 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.

Page 6: Master Child Packages

Calling a file based package

6) ExpressionGo 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.

Page 7: Master Child Packages

Expression on new connection manager

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

Master Child packages - Part 2: SQL Server based

Page 8: Master Child Packages

CaseAn 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

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

Page 9: Master Child 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 basedFor 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

Page 10: Master Child Packages

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

Page 11: Master Child Packages

3) Execute SQL TaskAdd 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

Page 12: Master Child Packages

12345678

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

SELECT   '\' + folders.foldername + '\' + packages.name as PackagePath --'Concatenate

FROM   msdb.dbo.sysssispackages as packagesINNER JOIN  msdb.dbo.sysssispackagefolders as folders    on folders.folderid = packages.folderidWHERE   folders.foldername = 'Staging'AND    packages.name like 'STG%'ORDER BY  packages.name

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

should be 0.

Result Set

Page 13: Master Child Packages

5) Foreach LoopAdd 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 EnumeratorEdit 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".

Page 14: Master Child Packages

Foreach ADO Enumerator

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

Page 15: Master Child Packages

Variable Mappings

8) Execute Package TaskAdd 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.

Page 16: Master Child Packages

Execute Package Task

9) ExpressionGo 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)

Page 17: Master Child Packages

10) Delay ValidationIf 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 resultA clear package with only one Execute Package Task.

Page 18: Master Child Packages

Master Child packages - Part 3: Project referenceCaseAn 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

Page 19: Master Child Packages

SolutionA 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 ReferencedFor 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.

Page 20: Master Child Packages

Get list of packages from SSISDB in SSIS 2012

1) VariablesAdd 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

Page 21: Master Child Packages

2) OLE DB Connection ManagerCreate 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

Page 22: Master Child Packages

3) Execute SQL TaskAdd 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

123456

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

SELECT      Packages.[name]FROM        [SSISDB].[internal].[packages] as PackagesINNER JOIN  [SSISDB].[internal].[projects] as Projects            on Packages.project_version_lsn = Projects.object_version_lsnWHERE       Projects.name = 'MasterChildPackages'

Page 23: Master Child Packages

78

AND         Packages.name like 'STG%'ORDER BY    Packages.name

4) Execute SQL Task - Result SetGo 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 LoopAdd a Foreach Loop Container to the control flow and give it a suitable name. Then connect the Execute SQL Task to the Foreach Loop.

Page 24: Master Child Packages

Foreach Loop Container

6) Foreach ADO EnumeratorEdit 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".

Page 25: Master Child Packages

Foreach ADO Enumerator

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

Page 26: Master Child Packages

Variable Mappings

8) Execute Package TaskAdd 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.

Page 27: Master Child Packages

Execute Package Task - Project Reference

9) ExpressionGo 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.

Page 28: Master Child Packages

Expression overrulling PackageName(path)

10) Delay ValidationIf 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

Page 29: Master Child Packages

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