SSIS包无法读取工作簿中的所有excell工作表

时间:2019-07-15 19:05:31

标签: excel vb.net ssis etl script-component

我正在用vb编写的脚本组件对旧的SSIS软件包进行故障排除。它实质上连接到excel工作簿,并通过一些上述选项卡进行读取。它会通过1、2或在最罕见的情况下随机读取所有选项卡,但大多数情况下只是通过第一个选项卡读取,并在开始通过第二个选项卡时无限期挂起。调试器在脚本组件上不起作用,因此没有太大帮助。

运行该程序包时,我已在脚本组件中的所有代码中放置了“消息”框,以便可以看到它正在执行的工作,还可以从某些工作表(主要是第一个)中看到生成的数据,但没有得到经过下一个工作表的下一个reader.read语句

Public Overrides Sub PreExecute()
    intImportType = Variables.ImportType

    Dim tableNameLower As String = Variables.ActiveWorkSheet.ToLower.Replace("'", "")

    Try
        Dim MaxReader As OleDbDataReader
        Dim MaxCmd As OleDbCommand
        Try
            MaxCmd = New OleDbCommand(Variables.MaxCommand, Conn)
            MaxReader = MaxCmd.ExecuteReader()
        Catch ex As Exception
            'MsgBox(ex.Message)
        End Try
        While (MaxReader.Read)
            MaxDate = CType(MaxReader.Item(0), Date)
        End While
        MaxReader.Close()
        MaxCmd.Dispose()
    Catch ex As Exception
        ' MsgBox(ex.Message)
    End Try

    ExpenseTable = CType(ReadVariable("User::ExpenseTable"), DataTable)

    Dim tableNameClean As String = tableNameLower.Replace("$", "").Trim
    Dim TabNameParts As String() = tableNameClean.Split(" "c)
    For Each ch As Char In TabNameParts(TabNameParts.Length - 1)
        If Char.IsDigit(ch) Then TabName += ch
    Next

    Try
        Dim cmd As New OleDbCommand(Variables.Command, Conn)
        reader = cmd.ExecuteReader
    Catch ex As Exception
    End Try
End Sub

Public Overrides Sub CreateNewOutputRows()
    If IsNothing(reader) Then Return

    Select Case intImportType

        Case ImportType.A

            Do While reader.Read
                    'reads these and other columns in file
                    part = reader("Part").ToString.Trim
            Loop

        Case ImportType.B

            Do While reader.Read

               'reads these and other columns in file
                    part = reader("Part").ToString.Trim

            Loop

            Dim Conn As OleDbConnection = New OleDbConnection(Connections.TestConnection.ConnectionString)
            Dim cmd As OleDbCommand
            Try
                Conn.Open()
                Dim sqlInsert As String = "UPDATE Table a SET valuea =" &  valueA
                cmd = New OleDbCommand(sqlInsert, Conn)
                cmd.ExecuteNonQuery()
            Catch ex As Exception
                MsgBox(ex.Message)
            Finally
                Conn.Close()
            End Try

        Case ImportType.C
            Do While reader.Read

               'reads these and other columns in file
                    part = reader("Part").ToString.Trim

            Loop
        Case Else
            Dim dt As DataTable = New DataTable
            dt.Columns.Add("D", GetType(D))
            dt.Columns.Add("E", GetType(E))

            'Dim partDictionary As New Generic.Dictionary(Of String, Integer)

            Do While reader.Read

            Dim iDate As Date = DateTime.MinValue
                Dim month As Date = DateTime.MinValue
                Try
                    iDate = Convert.ToDateTime(reader.GetValue(reader.GetOrdinal("IDate")))
                Catch ex As Exception
                End Try
                Try
                    Dim tmpMonthInvoiced As String = CStr(reader.GetValue(reader.GetOrdinal("Month")))
                    monthInvoiced = New Date(CInt(tmpMonthInvoiced.Substring(0, 4)), CInt(tmpMonthInvoiced.Substring(4)), 1)
                Catch ex As Exception
                    monthInvoiced = DateTime.MinValue
                End Try

                Dim TrxDate As Date = month
                If month = New Date Then TrxDate = iDate

                If Month(month) = Month(iDate) And Year(month) = Year(iDate)  
Then month  = iDate

If Not TrxDate = DateTime.MinValue And (Month(TrxDate) = Month(MaxDate) And 
Year(TrxDate) = Year(MaxDate)) Then
                    Dim row As DataRow = dt.NewRow
                    With row
                        .Item("Part") = reader("Part").ToString.Trim
                    End With

                    dt.Rows.Add(row)
                End If
            Loop

            For Each element As DataRow In expenseRows
                Dim tmpPartNum As String = CStr(element.Item("PartNumber"))

            Next

            For Each row As DataRow In dt.Rows
                With ResultBuffer
                    .AddRow()
                End With
            Next
    End Select
End Sub

该代码实际上只是在到达读者时挂起。在读取并生成工作簿中第一个工作表的输出之后读取

0 个答案:

没有答案