您的位置:首页 > 其它

SSIS的DelayValidation属性

2015-09-13 18:12 369 查看
一,DelayValidation Property

true if validation of the package is delayed until run time. false if the package is validated, and errors and warnings are returned before the package is actually executed. false may prevent the package from running if errors or warnings occur that exceed the MaximumErrorCount property.

DelayValidation Property is available on Task level, Connection Manager, Container and on Package level. By default the value of this property is set to false that means that when the package start execution, It validates all the Tasks, Containers, Connection Managers and objects( Tables,Views, Stored Procedures etc.) used by them. If any object such as table or destination file etc. is not available then Package validation fails and Package stop execution.

By setting this property to True, We enforce our SSIS Package not to validate that Task, Connection Manager or entire Package at start but validate at run time.

Validating the package before it runs is a way of finding some errors before execution starts. However, it processes the package to find errors, and if no errors are found, the package runs. Because this goes through the package two times, validating a package increases the amount of processing for the package, so should be used only when necessary.

二,SSIS的Validation 方式

SSIS使用Validation确定包在运行时是否会失败,它使用两种类型的验证,第一种是package validation,在开始执行包之前,验证包及其包含的所有组件,第二种是component validation,Task , Connection Manager和Container具有component validation,开始执行组件之前验证包中的所有组件。

如果Package的DelayValidation=False,那么Package Validation发生在Package执行之前,如果验证发现错误,Package不会被执行,直接报错。如果DelayValidation=True,那么Package执行之后第一步就是进行Package Validation,然后进行Component Validation。

Package 的DelayValidation Property影响Package运行时的Validation,如果DelayValidation Property被设置为false,那么在Package执行之前做Validation,如果一个组件引用一个不存在的staging表,那么package不会执行,并报错;如果DelayValidation Property被设置为true,package会执行,直到运行到该组件,才会进行Component Validation,发现错误后停止package的运行。

Component Validation是在Package Validation之后,组件执行之前所做的Validation。如果上流组件新建一个staging表,下游组件引用该staging表,并不会出现异常,这是因为在该组件进行Validation时,该staging表已经存在。

Component Validation在运行时进行验证的机制固定的,Task , Connection Manager和Container的DelayValidation Property影响的是打开包和design package时的验证行为。如果Task , Connection Manager和Container的DelayValidation Property设置为true,那么在打开包和design package不验证组件,直到执行该组件时才会进行验证。



By default run-time validation occurs in two phases:

1) Package-level validation (or 'early validation') - occurs when the Runtime calls the Excecute method of a package. EVERYTHING in the package gets validated.

If validation succeeds and the package commences its execute phase we come to

2) Component-level validation (or 'late validation') - occurs when the Runtime calls the Execute method for each and every task within the package.

This means that by default, all tasks within a package are validated twice!

As well as affecting the design-time validation of package components, 'Delay Validation = True' disables the Early Validation (package-level) phase so that only Component-Level validation occurs at run-time. NOTE that it's not possible to disable Component-level validation.

In general, delaying validation of all your components once you've finished development and are ready to deploy is a good option. It reduces overall package execution time (as early validation is skipped) and makes opening the package for editing less painful (as you don't need to wait for all the components to validate). Obviously, you may have scenarios where you want early validation to occur which is why I say in general so don't blindly delay validation without first considering the effect it will have on your package

三,打开包或design package时,SSIS会进行Validation

package在desgintime,runtime都会做validation。

在包级设置DelayValidation属性并不能阻止打开包时的最初的认证过程,它只是在我们运行包时延迟包级的验证,这就意味着包将继续运行,但是当我们打开包时警报仍然出现。如果我们也想阻止打开包时认证的话,必须将Task Level上的DelayValidation属性设置为True。

避免验证数据源是很有用的一个原因是,有时我们打开SSIS包的过程会花费很长的时间。这可能是因为这是一个远程数据源、数据源的响应是很缓慢的或者其它原因。如果我们正在开发一个包,并且我们需要经常打开这个包,那么我们可能需要花费很长的时间来等待SSIS验证一个数据源。在这样的情况下,在任务级设置DelayValidation属性为True将可以为我们节省大量的时间。

示例1,设置Package Level的属性DelayValidation=false,Task Level的属性DelayValidation=false

创建一个package,Control Flow design



Task Create Staging Table和Task Insert Data的sql语句分别是是

--Task Create Staging Table
if object_id('dbo.delay_test') is not null
drop table dbo.delay_test

create table dbo.delay_test
(id int)

--Task Insert Data,the table dbo.delay_test1 does not exist
insert into dbo.delay_test1
VALUES(1)


很奇怪,Package级别的Validation在Task Create Staging Table的Validation之前开始,在Task Insert Data的Validation之后结束,从图中能看到Execute Sql Task的Validate对sql语句进行Validation,但实际上没有检查出一个非常简单的错误。直到执行时,才发现错误。

我猜测可能的原因是Execute SQL Task不进行Early Validation,每次都是直到Task执行时才开始Validation。



将Task Insert Data 的sql语句修改为,两个Task执行成功。

--Task insert Data
insert into dbo.delay_test
VALUES(1)




示例2,设置Package Level的属性DelayValidation=false,Task Level的属性DelayValidation=false,在Data Flow Task中的OLE DB Source组件中从一个当前不存在的表dbo.delay_test中selelct数据,会出现异常。





在执行packge时,出现Package Validation Error的窗体,这就是package级别上的Validation



设置Package Level的属性DelayValidation=true,Task Data Flow Task的属性DelayValidation=false,重新执行package成功

示例3,打开package的验证

设置Package Level的属性DelayValidation=true,Task Level的属性DelayValidation=false,在打开package时,Task Data Flow Task上面是有红色X号的,当设置Task Level的属性DelayValidation=true时,在打开package时,Task Data Flow Task上面没有红色X号。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: