从 OracleBulkCopy 获取 ProgressBar 的运行时

get runtime from oraclebulkcopy for progressbar

提问人:Giancarlo 提问时间:7/22/2021 更新时间:7/22/2021 访问量:101

问:

晚安朋友们,

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

我正在尝试:

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

但它没有返回所需的结果,我必须将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:\2021\"
                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
.NET vb.net visual-studio-code

评论


答:

0赞 jmcilhinney 7/22/2021 #1

我从未使用过,所以我不打算尝试编写详细的代码示例。我刚刚阅读了相关文档,因此我可以在此基础上指出我认为您应该做什么。OracleBulkCopy

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

我不确定事件处理程序的参数将为您提供什么。如果它提供了到目前为止复制的行数,则可以将其分配给属性。如果它没有提供计数,那么你可以将 的值添加到属性中。eValueNotifyAfterValue