问题
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 namedExportTypeof data typeString. Also, placed theExecute SQL Taskon the Control Flow tab. This task will help to identify the value being passed to the variableExportType.
- 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.ExportDatawith the following strucutre.Idcolumn 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
SSISmenu --> selectedPackage Configurationoption. 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 typeXML Configuration file. Selected a path to store the file.
- Added the Value property of the variable
ExportTypeand the ConnectionString property of the connection managerSQLServerto the configuration file.
- On the Execute SQL Task, selected the Connection to be
SQLServerand set the SQLStatement property toINSERT 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.Ownerfield information is removed to hide sensitive information.
- On the SQL job's Steps page, created two steps named
Step_01andStep_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
ExportTypeto Schedule. Named the configuration file asScheduleConfig.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.dtsxas used by step 1.
- Copied the package configuration file created using the package and changed the value for the variable
ExportTypeto Unschedule. Named the configuration file asUnscheduleConfig.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