Control Flow 如何处理 Error
在Package的执行过程中,如果在Data Flow中出现Error,那么Data Flow component能够将错误行输出,只需要在组件的ErrorOutput中进行简单地配置,参考《Data Flow的Error Output》。相比Data Flow,Control Flow对OnError事件的处理更加复杂和精细,主要需要考虑到以下5个方面:
1,在Control Flow中,Package本身,Task 和 Container具有属性 MaximumErrorCount
2,OnError事件的 Event handler能够捕获Task或Container出现OnError事件,并对Error进行处理
3,Package的Execution Result 和 progress message 对于Error的处理
4,属性FailPackageOnFailure 和 FailParentOnFailure 控制Error向上传递
5,OnError事件能够向父组件传递,类似冒泡
一,默认情况下,当container 出现错误时,package执行失败
二,属性MaximumErrorCount
属性MaximumErrorCount Specifies the maximum number of errors before the executable fails,即指定Executable能够容纳的Error 数量,当达到属性MaximumErrorCount设置的上限值时,Executable执行失败,抛出Error。默认值是1,只要发生Error,组件就会Fail。
设置Execute SQL Task的属性MaximumErrorCount,没有效果,这个属性对Container 或 Package 不起作用。
1,设置Container的属性MaximumErrorCount=2,其子Task发生一个错误,执行情况如下图所示
子Task(Execute SQL Task)执行失败,其父Container执行成功,由于该Container 和 下游组件的优先约束是Success,因此package继续执行下游的组件。
在Progress 选项卡中,SSIS 报出Warning信息
Warning: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
SSIS Package 最终的执行结果是
失败的原因是Error会继续向父组件传递,直到传递到Root Level(Package),而Package的MaximumErrorCount=1.
2,修改Package的属性,将Package的属性MaximumErrorCount=2,查看执行结果
在Progress Tab中查看执行过程
[Execute SQL Task] Error: Executing the query "insert into dbo.test_env
values(1,N'test_error')" failed with the following error: "An explicit value for the identity column in table 'dbo.test_env' can only be specified when a column list is used and IDENTITY_INSERT is ON.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
三,属性FailPackageOnFailure 和 FailParentOnFailure
FailPackageOnFailure:如果设置为True,那么只要单个task失败,则整个package失败。默认值是False
FailParentOnFailure:如果设置为True,那么只要单个Task失败,则该Task的上层组件将将失败,Task的Parent组件是Container 或 Package。默认值是False。
在发生错误的Task上,这两个属性都是false,通过执行情况来看,这两个属性没有发挥任何作用。
四,OnError事件的Event handler
在一个OnError Event处理程序中,如果将Propagate属性设置为False,那么不需要修改Parent container的MaximumErrorCount属性,就能保证在发生错误后包可以继续运行。详细请阅读《Event的Propagate》。
1,为Container下的Execute SQL Task创建OnError Event handler
2,将OnError的Event handler的系统变量 Propagate设置为False
3,查看package的执行结果
从Progress中查看到的Error Msg是:
[Execute SQL Task] Error: Executing the query "insert into dbo.test_env
values(1,N'test_error')" failed with the following error: "An explicit value for the identity column in table 'dbo.test_env' can only be specified when a column list is used and IDENTITY_INSERT is ON.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
3,将Package部署到Integration Services Catalog中,查看执行的结果,Satus是Succeeded,Error messages中显示错误的信息。
五,结论
Control Flow中发生的任何错误,都会被SSIS Engine捕获;不管如何设置Task或Container的属性,只要发生错误,就会有Error Message产生。
Error 能够向上传递,当Error被OnError事件的 Event handler捕获,并且Propagate设置为False时,Error停止传递。
Package的Execution Result 和 Package中是否出现Error 无关。组件抛出Error,Package仍然可能执行成功,只不过progress中会记录Error message。
Appendix:
引用《Understanding MaximumErrorCount》:
When the number of errors occurring inside a container during execution reaches its MaximumErrorCount, the container’s ExecutionResult is changed to Failure if it is not already set to that state. A value of zero sets the error count threshold to infinity, disabling this functionality.
Errors and execution result are distinct concepts. A container’s internal logic may set its result independent of whether errors have been raised. It’s possible for a container to return success and yet have raised errors or to report failure without having fired any errors. The behavior controlled by MaximumErrorCount bridges between these two concepts, overriding the container’s internal logic to coerce a failed result when the specified number of errors occurs.
MaximumErrorCount’s triggering of a failure result does not terminate the container’s execution. However, the state of failure may be used to influence control flow via precedence constraints. Also, in the case of For and Foreach Loop containers, a failed ExecutionResult disables further iteration.
Some documentation asserts that MaximumErrorCount defines the number of errors that can occur before a container stops running. Based on extensive testing using Microsoft SQL Server Integration Services Designer Version 12.0.2344.23 where I was unable to reproduce MaximumErrorCount halting a container’s execution, I believe this documentation to be inaccurate.
Propagation
By default, errors bubble up from child to parent containers. Within a package, this propagation may be disabled for a particular container by having its OnError event handler or set the system variable Propagate to false. Note that this variable only affects propagation inside a package. Even when set to false, errors raised in a child package are still passed to the parent package.
Each container in a container hierarchy makes an independent determination of whether a propagated error causes its MaximumErrorCount threshold to be met. For example, an error bubbling up may cause a parent container to fail even though its child container reports success because the parent container’s MaximumErrorCount is set to a lower threshold.
Control Flow 如何处理 Error的更多相关文章
- Core Java Volume I — 3.8. Control Flow
3.8. Control FlowJava, like any programming language, supports both conditional statements and loops ...
- [译]Stairway to Integration Services Level 9 - Control Flow Task Errors
介绍 在本文中,我们会实验 MaximumErrorCount和ForceExecutioResult 故障容差属性,并且还要学习Control Flow task errors, event han ...
- 《CS:APP》 chapter 8 Exceptional Control Flow 注意事项
Exceptional Control Flow The program counter assumes a sequence of values ...
- Asynchronous JS: Callbacks, Listeners, Control Flow Libs and Promises
非常好的文章,讲javascript 的异步编程的. ------------------------------------------------------------------------- ...
- CSAPP Chapter 8:Exception Control Flow
prcesssor在运行时,假设program counter的值为a0, a1, ... , an-1,每个ak表示相对应的instruction的地址.从ak到ak+1的变化被称为control ...
- [翻译] TensorFlow 分布式之论文篇 "Implementation of Control Flow in TensorFlow"
[翻译] TensorFlow 分布式之论文篇 "Implementation of Control Flow in TensorFlow" 目录 [翻译] TensorFlow ...
- SSIS的 Data Flow 和 Control Flow
Control Flow 和 Data Flow,是SSIS Design中主要用到的两个Tab,理解这两个Tab的作用,对设计更高效的package十分重要. 一,Control Flow 在Con ...
- 关于Control flow
1.一个package包含一个control flow并且一个或多个data flow. (这个项目叫做 Integration services project,提供了三种不同类型的control ...
- SSIS ->> Control Flow And Data Flow
In the Control Flow, the task is the smallest unit of work, and a task requires completion (success, ...
随机推荐
- Windows Phone 8.1 新特性 - 常用的启动器
本篇为大家介绍一下 Windows Phone 8.1 中部分常用启动器的实现方式.分别是 呼叫电话.发送短信.发送邮件.添加约会到日历.启动地图.地图路线显示.地图下载 和 地图更新. 1. 呼叫电 ...
- 关于“线程间操作无效: 从不是创建控件’textBox1‘的线程访问它”异常的解决方法
线程间操作无效: 从不是创建控件“textBox1”的线程访问它 背景:通过一个辅助线程计算出的一个值赋给textBox1.text;解决办法:1.直接在窗体的构造函数中加:System.Window ...
- jquery Ajax获取本地json 以及xml文件
$(function() { $("#Button1").click(function() { //按钮单击事件 //打开文件,并通过回调函数处理获取的数据 $.get(" ...
- 用MOS管防止电源反接的原理
电源反接,会给电路造成损坏,不过,电源反接是不可避免的.所以,我么就需要给电路中加入保护电路,达到即使接反电源,也不会损坏的目的. 一般可以使用在电源的正极串入一个二极管解决,不过,由于二极管有压降, ...
- Dom4j 对XMl解析 新手学习,欢迎高手指正
废话不多,先看代码 public static void main(String args[]){ ReaderXml("d:/example.xml");//读取XML,传入XM ...
- MySQL JDBC 出现多个 SHOW VARIABLES 语句。
一次偶然的机会,show processlist 的时候,发现有个 Client 一直在执行 "mysql-connector-java-5.1.21 ( Revision: ${bzr. ...
- 《C#图解教程》读书笔记之一:C#和.NET框架
本篇已收录至<C#图解教程>读书笔记目录贴,点击访问该目录可获取更多内容. 一.在.NET之前的编程世界 C#语言是在微软公司的.NET框架上开发程序而设计的,首先作者给大家纠正了一下C# ...
- 使用DBUnit框架数据库插入特殊字符失败的查错经历
本文记录的是使用DBUnit测试框架进行数据库数据插入时,插入特殊字符失败的查错经历.希望能对向我这样的小白同学们在遇到类似问题时,能够有一些启发.背景:在写跟数据库交互模块的单元测试,数据库表中的e ...
- Linux系统性能统计工具Sar和实时系统性能监控脚本
sar(System Activity Reporter系统活动情况报告)是目前 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告,包括:文件的读写情况.系统调用的使用情 ...
- [自己动手玩黑科技] 1、小黑科技——如何将普通的家电改造成可以与手机App联动的“智能硬件”
NOW, 步 将此黑科技传授予你~ 一.普通家电控制电路板分析 普通家电,其人机接口一般由按键和指示灯组成(高端的会稍微复杂,这里不考虑) 这样交互过程,其实就是:由当前指示灯信息,按照操作流程按相应 ...