【问题标题】:Error Handling in SSISSSIS 中的错误处理
【发布时间】:2018-01-11 06:00:50
【问题描述】:

我创建了一个 SSIS 包,它从文件夹中获取 XML 文件并检查架构,如果架构失败,则包记录错误并将文件移动到错误文件夹。目前,我已经完成了所有要求,并且工作正常,除了我在执行结束时收到的错误消息。

  1. 验证 XML 文件

  1. 我收到的错误消息

  1. 我收到的错误消息

该软件包按预期工作正常。如何隐藏此错误消息?

更新 #1:

这是我的错误历史

这是我的 XML 模式验证任务属性。

【问题讨论】:

  • 执行包时收到的错误信息是什么? IE。如果您在 Visual Studio 中查看执行日志,您会看到什么错误消息?
  • 如何抑制错误可能取决于错误的严重程度。您已经向我们展示了 Visual Studio 中发生的错误的屏幕截图 一旦它运行并且发生了错误,在您按下停止调试之前,请转到“进度”选项卡并向下滚动以找到您收到的错误消息。 (注意 - 您可以在其属性中将任务的“失败包失败”设置为“假”,但可能还有其他解决方案,因此尚未作为答案)。
  • 感谢您的回复,我已经更新了问题。

标签: sql-server ssis etl sql-agent-job sql-agent


【解决方案1】:

建议

问题可能是由FailPackageOnFailureFailParentOnFailure 属性引起的。单击Validate XML 任务并在属性选项卡中更改这些属性值。 Control Flow 中的 Alos 转到属性并更改 MaximumErrorCount 的值,使其大于 1

您还可以在此链接中找到其他有用的信息:

使用脚本任务的解决方法

  1. 在你的包中添加 3 个变量:

    @[User::XmlPath] Type: String, Description: Store the Xml File Path
    @[User:XsdPath] Type: String, Description: Store the Xsd File Path
    @[User:IsValidated] Type: Boolean, Description: Store the result of Xml validation
    
  2. 添加脚本任务,选择XmlPathUser:XsdPath作为只读变量,IsValidated作为读写变量

  3. 将脚本语言设置为Visual Basic
  4. 在脚本编辑器中编写以下代码(这是整个脚本任务代码)

    #Region "Imports"
    Imports System
    Imports System.Collections.Generic
    Imports System.Data
    Imports System.Math
    Imports System.Text
    Imports System.Xml
    Imports System.Xml.Schema
    Imports Microsoft.SqlServer.Dts.Runtime
    #End Region
    
    <Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute()>
    <System.CLSCompliantAttribute(False)>
    Partial Public Class ScriptMain
        Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    
        Enum ScriptResults
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        End Enum
    
        Public Function LoadXml(xmlFilePath As String, xsdFilePath As String) As Boolean
            Dim settings As New XmlReaderSettings()
            settings.Schemas.Add(Nothing, xsdFilePath)
            settings.ValidationType = ValidationType.Schema
            Dim errorBuilder As New XmlValidationErrorBuilder()
            AddHandler settings.ValidationEventHandler, New ValidationEventHandler(AddressOf errorBuilder.ValidationEventHandler)
            Dim reader As XmlReader = XmlReader.Create(xmlFilePath, settings)
            ' Read the document...
            Dim errorsText As String = errorBuilder.GetErrors()
            If errorsText IsNot Nothing Then
                Return False
            Else
                Return True
            End If
        End Function
    
        Public Sub Main()
    
            Dts.Variables("IsValidated").Value = LoadXml(Dts.Variables("XmlPath").Value.ToString, Dts.Variables("XsdPath").Value.ToString)
    
            Dts.TaskResult = ScriptResults.Success
        End Sub
    
    
    End Class
    
    Public Class XmlValidationErrorBuilder
        Private _errors As New List(Of ValidationEventArgs)()
    
        Public Sub ValidationEventHandler(ByVal sender As Object, ByVal args As ValidationEventArgs)
            If args.Severity = XmlSeverityType.Error Then
                _errors.Add(args)
            End If
        End Sub
    
        Public Function GetErrors() As String
            If _errors.Count <> 0 Then
                Dim builder As New StringBuilder()
                builder.Append("The following ")
                builder.Append(_errors.Count.ToString())
                builder.AppendLine(" error(s) were found while validating the XML document against the XSD:")
                For Each i As ValidationEventArgs In _errors
                    builder.Append("* ")
                    builder.AppendLine(i.Message)
                Next
                Return builder.ToString()
            Else
                Return Nothing
            End If
        End Function
    End Class
    
  5. 使用带有表达式的优先约束来操纵验证成功和失败案例

脚本代码参考

【讨论】:

  • 我做了所有这些,它工作正常,包没有崩溃,并且倾向于连续工作。唯一的事情是,我收到此错误消息。由于我已经处理了第一张图片所示的 xml 架构错误,因此我不希望在执行包后出现错误消息(图 3)。这就是我需要的
  • 在这种情况下你不能删除它你可以使用ForceExecutionResult 但在这种情况下我没有帮助
  • 您可以使用脚本任务验证Xml,并将结果分配给变量,然后使用优先表达式来实现类似的情况
  • @RanjithVaradan 另外请注意,如果您停止显示来自任务的错误消息,其他错误将被忽略,这非常关键
  • 是否可以将 xml 模式验证结果保存在布尔变量中,然后强制此任务结果成功,然后使用表达式中的布尔变量处理错误文件?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-02
  • 1970-01-01
相关资源
最近更新 更多