Vb.net SSIS脚本任务限制onerror

Vb.net SSIS脚本任务限制onerror,vb.net,http,ssis,etl,script-task,Vb.net,Http,Ssis,Etl,Script Task,我有一个使用HTTP连接对象下载文件的脚本任务。此脚本任务是另一个包调用的包的一部分。有时无法建立连接。在这些情况下,如果连接尝试失败,我希望在最终引发错误之前重试连接多次 我试图实现这一点。它似乎起了作用,任务没有失败。但是,即使脚本任务没有失败,每次脚本任务中发生异常时,仍然会传播OnError事件。一旦控制从子包传递回父包,就会发生失败 Public Sub Main() Dim tryTimes As Integer = 0 Dim maxTimes As Integer = 4 W

我有一个使用HTTP连接对象下载文件的脚本任务。此脚本任务是另一个包调用的包的一部分。有时无法建立连接。在这些情况下,如果连接尝试失败,我希望在最终引发错误之前重试连接多次

我试图实现这一点。它似乎起了作用,任务没有失败。但是,即使脚本任务没有失败,每次脚本任务中发生异常时,仍然会传播OnError事件。一旦控制从子包传递回父包,就会发生失败

Public Sub Main()
Dim tryTimes As Integer = 0 
Dim maxTimes As Integer = 4 
While (True) 
    Try
        Dim nativeObject As Object = Dts.Connections("HTTP Connection Manager").AcquireConnection(Nothing)
            'Create a new HTTP client connection
        Dim connection As New HttpClientConnection(nativeObject)
        Dim filename As String = Dts.Variables("Working_File").Value
        connection.DownloadFile(filename, True)
        Dts.TaskResult = ScriptResults.Success
        Exit While
    Catch ex As Exception
        If (tryTimes < maxTimes) Then
            tryTimes = tryTimes + 1
            Thread.Sleep(30000) 
        Else 
            MsgBox(ex.Message)
            Dts.TaskResult = ScriptResults.Failure
            Throw
        End If
    End Try
End While
End Sub
Public Sub-Main()
Dim tryTimes作为整数=0
Dim maxTimes为整数=4
While(True)
尝试
Dim nativeObject As Object=Dts.Connections(“HTTP连接管理器”).AcquireConnection(无)
'创建新的HTTP客户端连接
Dim连接作为新的HttpClientConnection(nativeObject)
Dim文件名为String=Dts.Variables(“工作文件”).Value
connection.DownloadFile(文件名,True)
Dts.TaskResult=ScriptResults.Success
退出时
特例
如果(tryTimes

我希望得到一个解决方案,除非连接尝试失败一定次数,否则不会调用OnError事件

尝试编写相同的代码,在前4次尝试时发出警告,在第5次尝试时发出错误,我不确定它是否有效:

Public Sub Main()
    Dim tryTimes As Integer = 0 
    Dim maxTimes As Integer = 4 
    While (True) 
        Try
            Dim nativeObject As Object = Dts.Connections("HTTP Connection Manager").AcquireConnection(Nothing)
                'Create a new HTTP client connection
            Dim connection As New HttpClientConnection(nativeObject)
            Dim filename As String = Dts.Variables("Working_File").Value
            connection.DownloadFile(filename, True)
            Dts.TaskResult = ScriptResults.Success
            Exit While
        Catch ex As Exception
            If (tryTimes < maxTimes) Then
                tryTimes = tryTimes + 1
                Dts.Events.FireWarning(0, "Error ignored", _
                        "Retrying in 30 seconds", String.Empty, 0)
                Thread.Sleep(30000) 
            Else 
                Dts.Events.FireError(-1, "", "Error message: " & ex2.ToString(), "", 0)
                Dts.TaskResult = ScriptResults.Failure

            End If
        End Try
    End While
End Sub
Public Sub-Main()
Dim tryTimes作为整数=0
Dim maxTimes为整数=4
While(True)
尝试
Dim nativeObject As Object=Dts.Connections(“HTTP连接管理器”).AcquireConnection(无)
'创建新的HTTP客户端连接
Dim连接作为新的HttpClientConnection(nativeObject)
Dim文件名为String=Dts.Variables(“工作文件”).Value
connection.DownloadFile(文件名,True)
Dts.TaskResult=ScriptResults.Success
退出时
特例
如果(tryTimes
参考


您需要在尝试之外使用标签,在捕获中使用GoTo

    Public Sub Main()
        Dim tryTimes As Integer = 0
        Dim maxTimes As Integer = 4

RunCode: 'Label here
        While (True)

            Try
                'your code here

                Exit While
            Catch ex As Exception
                If (tryTimes < maxTimes) Then
                    tryTimes = tryTimes + 1
                    Thread.Sleep(30000)
                    GoTo RunCode 'after we catch the exception and eval tryTimes go back and retry
                Else

                    'MsgBox(ex.Message)
                    Dts.Events.FireError(-1, "", "Error message: " & ex.ToString(), "", 0)
                    Dts.TaskResult = ScriptResults.Failure
                    'Throw
                End If
            End Try
        End While
    End Sub
Public Sub-Main()
Dim tryTimes作为整数=0
Dim maxTimes为整数=4
运行代码:'标签在这里
While(True)
尝试
'您的代码在这里
退出时
特例
如果(tryTimes
这会捕获错误,但由于正在使用连接管理器,因此连接管理器对象似乎会触发另一个错误,该错误不会被拾取,并且仍然会导致包失败。