sqlserver2005 SSIS 之事件处理

在包执行时,各种可执行对象如包,foreach循环,for循环等容器,及其他各种任务都可以触发事件

当事件发生时你可以自定义事件处理程序.

1.首先我在控制流面板中添加一个脚本任务.故意抛出一个错误.



2.切换到事件处理程序.



可执行任务可以选择package,或者是foreach容器,及其他的任务.

我这里选择package ,点击连接创建一个错误捕获的事件处理程序


我从工具栏拖入一个脚本任务来处理错误.编辑脚本任务

点击设计"脚本按钮"
编辑如下代码

 1Imports System
 2Imports System.Data
 3Imports System.Math
 4Imports Microsoft.SqlServer.Dts.Runtime
 5
 6Public Class ScriptMain
 7
 8    ' The execution engine calls this method when the task executes.
 9    ' To access the object model, use the Dts object. Connections, variables, events,
10    ' and logging features are available as static members of the Dts class.
11    ' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
12    ' 
13    ' To open Code and Text Editor Help, press F1.
14    ' To open Object Browser, press Ctrl+Alt+J.
15
16    Public Sub Main()
17        '
18        ' Add your code here
19        '
20        MsgBox(Dts.Variables("ErrorDescription").Value.ToString)
21        Dts.TaskResult = Dts.Results.Success
22    End Sub

23
24End Class

25

执行看看结果把

选择 ctrl + F5 不调试执行.



好,正是我之前在脚本任务中抛出的错误, 事件错误处理就此搞定!

原文地址:https://www.cnblogs.com/yg_zhang/p/499841.html