1

I am troubleshooting an old SSIS package with a script component written in vb. It essentially connects to an excel workbook and reads thru some of said tabs. It will randomly read thru maybe 1, 2 or in the rarest case all of the tabs, but mostly just reads thru the first one and hangs indefinitely when it starts reading thru the second one. Debugger does not work on script component so that is not much help.

When running the package I have placed Message boxes all over the code in the script component so I can see it doing it's job, I can also see resulting data from some of the worksheets (mostly the first) but it does not get past the next reader.read statement for the following worksheet

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

The code essentially just hangs when it gets to a reader.read after reading and generating output for the first of the worksheets in the workbook

Hadi
  • 36,233
  • 13
  • 65
  • 124
yaly_cu
  • 65
  • 1
  • 1
  • 3

0 Answers0