Run SSIS Package with 2 Different Configurations

时光毁灭记忆、已成空白 提交于 2020-01-15 07:10:26

问题


We have a SSIS job called ExportData and it accepts the 'ExportType' Parameter. The ExportType parameter can be 'schedule' or 'unschedule'.

I created the Variable called '@ExportType' and created the SSIS Configuration and expose the variable in the Configuration file and called it 'ScheduleConfig'. I copied that file and change the value to 'unschedule' and called it 'UnscheduleConfig'.

I created the SSIS Job in the SQL Server 2008 and set up 2 steps for both 'Schedule' and 'Unschedule'. I attached the correct config file for each Step. But whichever step I run, it always execute 'Schedule'. I am sure and double checked the Config files and Steps.

How can I run 2 different jobs with 2 different configuration files?

I did try by using the SetValues method and it doesn't work too.


回答1:


If I understand your requirements correctly. here is a sample package created in SSIS 2008 R2 and does what you are looking for. The sample uses a single package, which is executed under two different SQL agent job steps and both the steps use a different copies of the same configuration file. The configuration files hold different values for the variable used inside the package.

  • Created a sample SSIS package named SO_10177578. Within the package, created a package variable named ExportType of data type String. Also, placed the Execute SQL Task on the Control Flow tab. This task will help to identify the value being passed to the variable ExportType.

  • Added the OLE DB connection to a sample database and named the connection as SQLServer. I chose to use SQL Server authentication for this connection manager.

  • Within the SQL database, created a table named dbo.ExportData with the following strucutre. Id column is a identity column.

  • The table doesn't contain any data to begin with. This table will be populated with data when the package is executed.

  • On the SSIS package, clicked on the SSIS menu --> selected Package Configuration option. On the Package Configurations Organizer dialog, selected the Enable package configurations checkbox and clicked on the Add button. Created a new package configuration of the type XML Configuration file. Selected a path to store the file.

  • Added the Value property of the variable ExportType and the ConnectionString property of the connection manager SQLServer to the configuration file.

  • On the Execute SQL Task, selected the Connection to be SQLServer and set the SQLStatement property to INSERT INTO dbo.ExportData (PackageName, ExportTypeValue) VALUES (?, ?)

  • Configured both the parameters to the appropriate variables available on the package. Now the package is ready for deployment.

  • On the database server's SQL Agent node, created a new SQL job named Test_ExportData. Owner field information is removed to hide sensitive information.

  • On the SQL job's Steps page, created two steps named Step_01 and Step_02.

  • Step 1 is configured as below with the package being stored in the path c:\temp\SO_10177578.dtsx.

  • Copied the package configuration file created using the package and changed the value for the variable ExportType to Schedule. Named the configuration file as ScheduleConfig.dtsConfig. Screenshot shows only part of the configuration file to hide sensitive connection string information.

  • In step 1 of the job, referred the newly created package configuration file from the path c:\temp\Test\ScheduleConfig.dtsConfig.

  • Step 2 is configured as below and it uses the same package stored in the path c:\temp\SO_10177578.dtsx as used by step 1.

  • Copied the package configuration file created using the package and changed the value for the variable ExportType to Unschedule. Named the configuration file as UnscheduleConfig.dtsConfig. Screenshot shows only part of the configuration file to hide sensitive connection string information.

  • In step 2 of the job, referred the newly created package configuration file from the path c:\temp\Test\UnscheduleConfig.dtsConfig.

  • Now, both the steps are configured. Executed the new SQL agent job.

  • Queried the table ExportData. You can notice that the package was executed twice and each execution in the SQL agent job's steps used the appropriate configuration files specified on the steps.

Hope that helps.




回答2:


I suggest you not store @ExportType in an SSIS Configuration. You can override the value from the DTEXEC command line by adding a SET switch similar to:

/SET "\Package.Variables[ExportType].Properties[Value]";Schedule

You can use the same PackagePath above to override this variable value in the SQL Agent Integration Services Job Step Type on the Set Values tab.

Hope this helps, Andy




回答3:


you cant do that. The SSIS wont read the new configuration.

You need to call the package twice, one time with config file A and one time with config file B. On each config file you will have the @ExportType variable set to 'schedule' and 'unschedule'.

You can only set a parameter once. Even if you use DTEXEC with the /Config option for example you CANT overwrite a parameter that is already set



来源:https://stackoverflow.com/questions/10177578/run-ssis-package-with-2-different-configurations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!