简体   繁体   English

SSIS计划并重新启动程序包执行

[英]SSIS schedule and restart package execution

I want to avoid duplicate SSIS operations when the SQL Server restarts. 我希望在SQL Server重新启动时避免重复的SSIS操作。

I've set a job with a single step (to run a SSIS package which has an infinite loop itself). 我已经设置了一个步骤(运行一个本身具有无限循环的SSIS程序包)。 This job is scheduled to run "when the Sql Server Agent starts". 该作业计划在“ Sql Server代理启动时”运行。

When the SQL Server Agent is restarted, the job is also restarted and the Active Operations in my SSIS catalog show a single running Task, which is good. 重新启动SQL Server代理后,作业也会重新启动,并且SSIS目录中的“活动操作”显示单个正在运行的任务,这很好。 But when the Windows Server itself is restarted, the Active Operations shows two running Tasks, and they are both the same -> https://imgur.com/a/l8pJbbl 但是,当Windows Server本身重新启动时,活动操作将显示两个正在运行的任务,并且它们都是相同的-> https://imgur.com/a/l8pJbbl

I expect only a single Active Operation whether I restart the Windows Server or the SQL Server Agent. 无论我重新启动Windows Server还是SQL Server代理,我都希望只有一个活动操作。 How can I achieve this? 我该如何实现?

In the job step, execute the package from the SSIS catalog using T-SQL and add a condition to check if the package is already active. 在作业步骤中,使用T-SQL从SSIS目录执行该程序包,并添加条件以检查该程序包是否已处于活动状态。 In the example below the catalog.executions DMV is queried for a package by the given name with a status of 2, which represents a currently running package. 在下面的示例中,使用给定名称(状态为2)查询给定名称的软件包的catalog.executions DMV,它表示当前正在运行的软件包。 If this package is found already active then nothing is done, otherwise it is executed from the catalog.start_execution stored procedure. 如果发现此程序包已经处于活动状态,则什么也不做,否则从catalog.start_execution存储过程执行该程序包。

IF NOT EXISTS(SELECT EXECUTION_ID FROM SSISDB.CATALOG.EXECUTIONS WHERE PACKAGE_NAME = 'YourPackage.dtsx' 
AND PROJECT_NAME = 'ProjectOfPackage' AND FOLDER_NAME = 'Folder Containing Package' AND [STATUS] = 2)
BEGIN 

DECLARE @execution_id bigint
EXEC [SSISDB].[catalog].[create_execution] @package_name=N'YourPackage.dtsx', @execution_id=@execution_id OUTPUT, 
@folder_name=N'Folder Containing Package', @project_name=N'ProjectOfPackage'

DECLARE @var0 smallint = 2
EXEC [SSISDB].[catalog].[set_execution_parameter_value] @execution_id,  @object_type=50, 
@parameter_name=N'LOGGING_LEVEL', @parameter_value=@var0

EXEC [SSISDB].[catalog].[start_execution] @execution_id

END

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM