Академический Документы
Профессиональный Документы
Культура Документы
http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/66426/
Printed 2009/10/05 01:25PM
http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/66426/Printable
05-10-2009
Pgina 2 de 6
-- View used in package configuration to select properties by environment CREATE VIEW dbo.SSIS_Config AS SELECT ConfigurationFilter, PackagePath, ConfiguredValueType, ConfiguredValue FROM dbo.SSIS_Config_base b JOIN( -- Choose environment based on where package is running SELECT CurrentEnvironment = CASEWHEN HOST_NAME()= '<production server>' THEN 1 WHEN HOST_NAME()= '<test server>' THEN 3 ELSE 2 END) e ON b.EnvironmentEnum = 0 OR b.EnvironmentEnum = e.CurrentEnvironment
The subquery in the view is the key concept here. I show a choice of three environments based on the HOST_NAME () function, but you are only limited by your imagination. More environments can be defined, and there are many different ways to define them. The point is that if you can write a subquery that correctly chooses the environment for package configuration on your systems, that works wherever the package might run and whoever runs it, this view can select the correct configuration set from one central table. Other possible inputs are USER_NAME() and PROGRAM_NAME() (this can be set in a package using the Application Name property of the SQL config connection manager). If your rules cant be boiled down to one expression, you could have another table that defines the environment for every combination of user, host, and program name. To elaborate, I added a tinyint field to the standard configuration table named EnvironmentEnum that has values in the range 0-3. Properties that are the same in all environments have one record with a value of 0, properties with alternate values have three records enumerated 1, 2, and 3 to provide separate values for each environment. It works seamlessly with package development. When new configuration sets are created they default to a single allenvironment record (enum=0). Single-valued properties can be modified and saved in BIDS as usual, and if a multivalued property is modified and saved only the development version is affected. There are stored procedures in the code file to split single-valued properties into multi-valued, merge them back to single-valued, and to set all alternate values for a given property. To see all alternative settings for each property requires a PIVOT view.
/* SSIS Configuration multi-environment maintenance view View one config item per line with all variations by pivoting on environment
*/ CREATE VIEW dbo.SSIS_Config_AllEnv AS SELECT ConfigurationFilter, PackagePath, SUBSTRING(t.ConfiguredValueTypeList, 4, 999) AS ConfiguredValueType, [0] AS GlobalValue, [1] AS ProductionValue, [2] AS DevelopmentValue, [3] AS TestValue FROM( SELECT ConfigurationFilter, PackagePath, EnvironmentEnum, ConfiguredValue FROM SSIS_Config_base )base PIVOT(MAX(ConfiguredValue) FOR EnvironmentEnum IN ([0], [1], [2], [3])) pvt -- Use CROSS APPLY ... FOR XML PATH trick to concatenate different ConfiguredValueType entries -- There shouldn't be any differences, but if there are it should be made obvious -- The initial space-semicolon-space delimiter is removed by SUBSTRING above CROSS APPLY ( SELECT DISTINCT' ; ' + ConfiguredValueType FROM dbo.SSIS_Config_base WHERE ConfigurationFilter = pvt.ConfigurationFilter AND PackagePath = pvt.PackagePath FOR XML PATH('') ) t ( ConfiguredValueTypeList )
http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/66426/Printable
05-10-2009
Pgina 3 de 6
I created a simple demonstration package that uses a script task to produce a message box built from package variables. The variable value properties were assigned to a new configuration set. Note that the Configuration String refers to the above view, not the table.
http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/66426/Printable
05-10-2009
Pgina 4 de 6
With the original design values, running the package produces this dialog:
Now I go to Management Studio and expand the configured properties to have different values. This screen shot shows how the items were created originally by BIDS, and what they look like afterwards.
This screen shot shows the underlying records in the base table. When the package is loaded it will pick one consistent subset of these records through the SSIS_Config view. A production package will probably have many configuration sets, and the correct subset of each of them will be used.
http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/66426/Printable
05-10-2009
Pgina 5 de 6
I saved the package to msdb on my production server, although it could have been saved to a file share or any other location visible from all the target environments. Then I ran the package from my laptop, the test server, and the production server to show the three different configurations. Note that I only had to deploy one copy of the package, and no additional files or other artifacts.
Its more impressive when youre reconfiguring connections and controlling the package on a grander scale, but hopefully this demo shows how the technique works. My packages, when not in production, automatically connect to different servers, use local test FTP sites, dont send email outside our department, and log to a different location. I think this is the easiest solution for my needs. It is easy for developers who are new to SSIS to pick up, especially since I created a template package that has configuration, logging, error handling, and email all set up. I dont have to worry about developers accidentally wiping out production data or sending erroneous emails to customers. If a package reports an error I can easily check what configuration settings it is using, and if necessary who was the last person to change them. The attached code file has the complete code for all tables, views, and procedures. An unrelated issue with SQL
http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/66426/Printable
05-10-2009
Pgina 6 de 6
Server configuration tables that I found while researching this project is that the ConfiguredValueType field is casesensitive when used by SSIS, and improperly-cased values cause the configuration item to be ignored with no warning. The table definition in the code file shows how to use a case-sensitive collation and check constraint to only allow proper-cased values for ConfiguredValueType. Copyright 2002-2009 Simple Talk Publishing. All Rights Reserved. Privacy Policy. Terms of Use
http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/66426/Printable
05-10-2009