从 oraclebulkcopy 获取进度条的运行时

get runtime from oraclebulkcopy for progressbar

晚安朋友们,

我正在上传文件 从繁重的 excel (200 MB) 到 oracle,我正在使用 BackgroundWorker1 在后台处理它,但我无法计算执行时间或执行 oraclebulkcopy 以便能够循环和更新所需的时间计数器并将其传递给进度条。

我正在尝试:

for i: 0 to row_file_excel
BackgroundWorker1.reportprogress (i)
next

但它没有 return 想要的结果,我必须将 row_file_excel 替换为加载 oraclebulkcopy 所需的时间,但我不知道如何找到工作时间。

如果获取不到时间,我还能做什么?

如有任何帮助,我将不胜感激

非常感谢,

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim _connString As String = "Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.100.1)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = ORACLE))); User Id=USER; password=PASS;"
        Dim rutacarpeta As String
        Dim NombreArchivo As String
        Dim tablaBBDD As String
        'Dim ot As OracleTransaction = conn.BeginTransaction(IsolationLevel.ReadCommitted)
        Using conn As OracleConnection = New OracleConnection(_connString)
            conn.Open()
            Dim ot As OracleTransaction = conn.BeginTransaction(IsolationLevel.ReadCommitted)
            Try

                rutacarpeta = "C:21\"
                NombreArchivo = "FILE_0.xlsx"
                tablaBBDD = "FILE_TEST"
                Dim xlsxConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR=Yes;IMEX=1;';"
                xlsxConn = String.Format(xlsxConn, rutacarpeta + NombreArchivo).Trim()

                Using excel_con As OleDbConnection = New OleDbConnection(xlsxConn)
                    excel_con.Open()
                    'Dim hoja As String = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing).Rows(0)()
                    Dim command As OleDbDataAdapter = New OleDbDataAdapter ("SELECT * FROM [FILE$]", excel_con)

                    Dim dtset As new dataset
                    command.fill(dtset)
                     dim dr as datatable =dtset.tables(0)
                     row_file_excel=dr.rows.count

                    Using bulkCopy As OracleBulkCopy = New OracleBulkCopy(conn)
                        bulkCopy.BulkCopyTimeout = 90000
                        bulkCopy.DestinationTableName = tablaBBDD

                  for i: 0 to row_file_excel '***here I want to calculate the execution time of the load (bulkCopy.WriteToServer(dr))******
                      BackgroundWorker1.reportprogress(i)
                  next                            

                   bulkCopy.WriteToServer(dr)

                        ot.Commit()

                        bulkCopy.Close()
                    End Using
                End Using

            Catch ex As Exception
                Try
                    ot.Rollback()
                Catch ex1 As Exception
                    MessageBox.Show(ex1.Message)
                End Try

                MessageBox.Show(ex.Message)

            End Try
        End Using
    End Sub

我从来没有用过OracleBulkCopy所以我不会尝试编写详细的代码示例。我刚刚阅读了相关文档,所以我可以根据它指出我认为你应该做的事情。

检索数据时,您可以获得要导入的记录总数并将其分配给 ProgressBarMaximum 属性。您可以设置 NotifyAfter 属性 并处理 OracleBulkCopy 对象的 RowsCopied 事件,以便在每次复制多行时得到通知。您指定的数字越小,事件引发的频率就越高,您的进度就越细粒度,但您就越会减慢整个过程。您可以根据每个事件复制的行数来增加 ProgressBarValue

我不确定事件处理程序的 e 参数会为您提供什么。如果它提供了到目前为止复制的行数,那么您可以将其分配给 Value 属性。如果它不提供计数,那么您只需将 NotifyAfter 的值添加到 Value 属性.