未加星标

How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks

字体大小 | |
[数据库(mssql) 所属分类 数据库(mssql) | 发布者 店小二04 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏

By:Dinesh Asanka | Last Updated: 2018-12-06 || Related Tips:More > Integration Services Control Flow Transformations

Problem

In the Control Flow of a SQL Server Integration Service (SSIS) package there can be cases where some control flow tasks are dependent on outside resources. For example, there can be control flows where it will copy files from one server to another or there can be cases where file compression is taking place. Since these are error prone activities, there can be cases where the entire package will fail. Therefore, there should be a method to retry the process in the event of a failure. However, the retry should take place only when there is a failure and only for limited number of tries otherwise the package could run forever.

Solution

There is no built-in feature in SSIS with this functionality, therefore you need to configure SSIS to achieve the above objectives.

Example SSIS Package Using Copying a File

Let's see simple an implementation of a file copy using the File System Task in the SSIS control flow.


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks

Let's configure this for a simple file copy as shown in the below image.


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks

When this is executed, it will execute as long as the destination path and the source file is available. In the case where any of these are not available, the task will fail which will cause the entire package to fail.

SSIS Package Retry Option

The requirement is that in the event the file is not available, it should automatically try again for a defined number of times with a specified wait interval between tries. This type of feature is available in SQL Server Agent Jobs as shown below. In the Advanced tab of the SQL Server Agent job step configuration, the user has the option of configuring the Retry attempts and the Retry intervals .


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks

So, if you use this option in a SQL Server Agent job, the entire package will re-execute when a task fails. You can utilize this option, but you need to modularized your SSIS packages which could become difficult to manage.

So, what we are looking at is having a SSIS option to retry when is there is a failure.

The following SSIS implementation could be used which includes a For Loop Container, Expression (EXIT) and SQL Execution Task (WAIT).


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks

To do this, we need two integer variables to be defined. Variable I is the running variable while variable RetryCount is number of retries it should make. The boolean variable UntilSuccess is used as a flag for successful execution.


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks

With these variable definitions, in case there is a need to change the retry times, it is just a matter of changing the RetryCount variable value.

In the For Loop Editor, there are three properties to set: InitExpression, EvalExpession and AssignExpression. The initial configurations are shown in the below image.


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks
Success Path

For the Success path, when there is success, variable I will be set to the RetryCount and the loop will stop and exit.


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks
Failure Path

The Failure path is little more complex than the success path as there are few more configurations.

The WAIT will be done using the T-SQL command WAITFOR DELAY ’00:00:05’. This delay is 5 seconds, however you can configure it suit to your needs. You will need to have a SQL Server connection to execute this T-SQL statement.


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks

If you need to configure the delay, you can configure this value as a variable and modify the above code.

Next is configuring the expression in the failure path flow. This configuration is only needed, if you are configuring your package to execute until it is successful. If not, you don’t need this path.

This expression is, if the UntilSuccess variable is true, variable I will be set to 0 if not it will be incremented by 1.


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks

When it is set to 0, the For Each Loop will execute until the file copy is successful.

Next is an important configuration in the For Loop Container. In the property window of the For Loop Container, the MaximumErrorCount default value is 1. This means this will fail after one error. This value needs to be set to 0 or it should be set to number of retries which means that controller will not fail.


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks

That is all you need to do in order to configure the SSIS package to retry.

Execution of the SSIS Package

When the package executes, if the file copy fails, the package will take following execution where it takes the failure path and tries again.


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks

When the package executes successfully after a few attempts, we can see the flow in the Progress window as shown below. The below shows the file copy is successful after a couple of failure attempts.


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks
Next Steps Implement retry configuration with SSIS by following above steps. Check out these otherSSIS tips

Last Updated: 2018-12-06


How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks
How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks
About the author
How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks
Dinesh Asanka is a 10 time Data Platform MVP and frequent speaker at local and international conferences with more than 12 years of database experience. View all my tips

Related Resources

More Business Intelligence Tips...

本文数据库(mssql)相关术语:熊片数据库 mssql数据库 oracle数据库 pubmed数据库 access数据库 万方数据库

代码区博客精选文章
分页:12
转载请注明
本文标题:How to Retry SQL Server Integration Services (SSIS) Control Flow Tasks
本站链接:https://www.codesec.net/view/621151.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(mssql) | 评论(0) | 阅读(51)