如何获取解决方案中所有 SSIS 包的所有错误

How to get all errors of all SSIS packages in a solution

在 Visual Studio 2015 年,我在 SSIS 包文件夹中有一个包含 3 打 dtsx 的解决方案。我重新构建解决方案并获得成功。只有当我一个接一个地打开单个 dtsx 时,我才注意到其中一些(不是全部)实际上有几个问题。

有没有办法在错误列表中获取这些问题的列表,或者我是否需要一个一个地打开所有 dtsx

不幸的是,如果不打开包或使用 DTExec Utility 执行它们,则无法从您的集成服务解决方案(在 visual studio 中)实现这一点。但是您可以采取一些解决方法并以编程方式检查获取错误:

解决方法

  1. 我使用 visual studio 创建了一个 winforms 应用程序(使用 Vb.Net)
  2. 我添加了 Microsoft.SqlServer.DTSPipelineWrapMicrosoft.SQLServer.ManagedDTS 作为参考
  3. 我使用以下代码遍历特定目录中的包,验证并将错误记录到日志文件中:

    Dim strPackagesDirectory As String = "C:\Users\Admin\Desktop\New folder"
    Dim strOutputLogFile As String = "D:.txt"
    
    For Each strFile As String In IO.Directory.GetFiles(strPackagesDirectory, "*.dtsx", IO.SearchOption.TopDirectoryOnly)
    
        Dim pckg As New Microsoft.SqlServer.Dts.Runtime.Package
        Dim app As New Microsoft.SqlServer.Dts.Runtime.Application
    
        pckg = app.LoadPackage(strFile, Nothing)
        Dim obj = pckg.Validate(Nothing, Nothing, Nothing, Nothing)
    
        If pckg.Errors.Count > 0 Then
    
            Using sr As New IO.StreamWriter(strOutputLogFile, True)
                sr.WriteLine("")
                sr.WriteLine(strFile)
                sr.WriteLine("--------------")
                For Each err As Object In pckg.Errors
    
    
                    sr.WriteLine(err.Description)
    
                Next
    
                sr.WriteLine("==========")
                sr.Close()
            End Using
    
        End If
    Next
    

参考资料