Once you have completed a set of packages, the challenge is to deploy those packages to a production environment without having to manually reconfigure them for that environment. For example, you may have to get source files from a different directory or the source databases may be on a different server than your production environment.
Configuration tables help automate migration and reduce the risk of deployment-related errors. You can use a configuration table that contains the ConnectionString property value for each connection. Each package that uses the connection can obtain the ConnectionString from the configuration table. As part of the initial deployment to production, you create another configuration table, like the one used in development. You then copy the rows from the development configuration table to the production configuration table, changing the values for the ConnectionStrings to point to production sources and destinations. When the packages are moved to production, you can change the configuration table’s server name from the development server to the production server.
This capability is not limited to connection strings. The SSIS Package Configuration option enables you to store any SSIS property for the package, connection, container, variable, or any task into a table. You will have a configuration table in the development environment that contains values for all of the properties that need to be changed for production. A similar configuration table will exist in production, but you will set values of the properties appropriately for production.
For example, say your source database server name in the development environment is TestSQL and in production it is Prod. Your configuration table in both environments would contain a row that defines the connection property of the source database connection manager. However, the values contained in the row in the development environment refer to TestSQL, and the production row refers to Prod. While the package is in development, the development configuration table is used. When the package is moved to the production server, it is configured to use the production configuration table. Once set up, this process makes deployment easier, repeatable, and less error-prone.
Here is an example where you use a configuration table to set the connection string for your source database.
First, create a project and an empty package. Add a connection manager to the package. For this example, you can use any database on any server. After you have created the connection manager, change its name to SourceDatabase.
To use tables for configuration, your project must use the package deployment model. Because this is not the default, you must convert your project. Right-click your project and choose Convert to Package Deployment Model. You can see how to do this in Figure 44-1.
SSIS performs a check to ensure the packages in your project are compatible with package deployment and provides a report, as in Figure 44-2. Click OK. All of the packages within this project will be converted.
Create another connection manager that points to the development server where you will place the configuration table. Name this configuration manager ConfigurationDatabase.
First you create the configuration table and then set the connection property for the SourceDatabase Connection Manager.
To create the configuration table for a package, right-click in the blank area of the package in the Control Flow window and choose Package Configurations, as shown in Figure 44-3.
This action opens the Package Configurations Organizer. This window enables you to create, edit, and delete package configurations. Check the Enable package configurations check box, as shown in Figure 44-4.
To create the connection to the configuration table, click the Add button at the bottom of the Package Configurations Organizer. This starts the Package Configuration Wizard. The first time you add a configuration table, you see a welcome screen; you can check the option to not show this page again if you prefer. Click Next to move on.
On the next screen, select SQL Server from the Configuration Type drop-down menu. With SQL Server as the type, you can create your connection table in any SQL Server database. You can click the New button to the right of the Connection drop-down to create an OLE DB connection to a SQL Server instance. Choose the ConfigurationDatabase Connection Manager you created earlier. This connection is strictly for the package’s connection to the configuration table. Data in this table contains connection strings and other configuration property values. You will store the connection string for the SourceDatabase in this table.
After you have selected the SQL connection, select the table to use. There is a default table named SSIS_Configurations. You can choose a preexisting configuration table in the database, if one exists. You can also create a new table. To create a new table, click the New button next to the Configuration Table drop-down menu. This opens the SQL query that creates the table.
Many packages may use the same configuration table. You can group collections of properties together and give them a name called a filter name. A package may request a particular set of configuration rows by using the filter name. You can choose a previously defined collection by choosing the filter from the drop-down, or you can type in a new filter name. You need to make this name broad yet descriptive. You will see this filter listed when you set up configuration rows in this table for other packages. In this example, this group of configurations contains only the connection string for your source database, which is your Enterprise Resource Planning (ERP) system. Therefore, you will create a filter called “ERPSource.” Once you select the SQL Server and the table, the window should look like Figure 44-5.
After you click Next, you see the list of objects in the package and the attributes for those objects. You can place a check next to each attribute you want to include for this filter in the objects list in the left pane. In the right pane, type the value that will be stored in the configuration table for the selected property. Check the ConnectionString property for the SourceDatabase connection. Then you can set the value for this property in the right pane, as in Figure 44-6.
Now you can click Next and go to the final configuration window, where you can name the configuration. This name is used for reference in this package only. You also see the configuration type, connection name, table, filter, and the target property (Figure 44-7).
Click Finish to return to the Package Configurations Organizer. You can now see the new configuration listed in this window, as shown in Figure 44-8. Your configuration contains the connection string that is used to connect to the source database for your extract process. The Add, Edit, and Remove buttons at the bottom of this window enable you to alter or remove the existing configuration tables and add new ones.
Once you have a configuration defined for a package, the package will use the property values from the configuration table instead of the design-time values stored in the package.
If some properties included in the filter group do not exist in the package, they are simply ignored. For instance, if your filtered collection contains some properties for a connection named DestinationDB and that connection does not exist in your package, there is no error, and those configuration rows are not used for this package.
In this Try It, you learn how to create a configuration table and use the data from the configuration table. After this lesson, you should understand how configuration tables are used to pass information into a package.
The completed packages for this lesson are available for download on the book’s website at www.wrox.com.
In this lesson, you create a simple package with a Script Task that pops up a message with the configuration value instead of the value saved in the package. Then you create a configuration table and run the package to see the value in the configuration table.
MsgBox(Dts.Variables(“strConfigTest”).Value)
In most cases, the connections you need will be different in each environment. For example, in development, you may have a SQL server named Dev. However, in production the server is named Prod. As you move your package from development to production, the connections will have to change. To reduce the possibility of newly introduced errors, you should be able to change the configuration from development to production without having to open, edit, and re-save your package. This is how you handle the final deployment to production.
After you have created the configuration tables in both development and production and set the values appropriately, you have one more thing to do. The connection string that points to the configuration table will need to be different in production. You can set this in several ways:
You can learn more about deployment and scheduling of packages in Lessons 53 and 59.