[英]Executing a SQL Update batch within a transaction
The problem is that the datatable will have anywhere from 10,000 to 50,000 rows and by cmd.executenonquery firing on every iteration is inefficient and takes longer than it should. 问题在于数据表将具有10,000到50,000行的任何位置,并且通过cmd.executenonquery触发每次迭代效率低下,并且所需时间更长。
Dim db As New PGS.DBConnection
Try
db.BeginTransaction()
For Each row As DataRow In dt.Rows
Dim ParameterList(24) As SqlParameter
ParameterList(0) = New SqlParameter("ProjectID", ProjectID)
ParameterList(1) = New SqlParameter("Discipline", row("Disc"))
.
.
.
ParameterList(24) = New SqlParameter("User", username)
db.ExecuteQuery("EstimateInsert", ParameterList)
Next
db.CommitTransaction()
Return "success"
Catch ex As Exception
db.RollbackTranscation()
Dim db2 As New PGS.DBConnection
db2.InsertError(ex.Message, ex.StackTrace, ex.Source, "Excel Estimate Processing", HttpContext.Current.User.Identity.Name)
Return ex.Message
End Try
The DBconnection object is handles the using functions to open, execute, and close all things sql. DBconnection对象处理使用函数来打开,执行和关闭所有sql。 In this case giving it a stored procedure name and an array of SQL parameters
在这种情况下,为其提供存储过程名称和SQL参数数组
I don't have to shoe-horn a fix into this framework and if I need to rewrite the entire thing that is fine. 我不必费劲去解决这个框架,如果我需要重写整个事情的话。
Is there a way to run a set a batch size of 500 and speed it up? 有没有一种方法可以运行500个批次的批处理并加快处理速度? Let me know if you need any more code posted...thanks!
让我知道是否需要发布更多代码...谢谢!
错误处理的B / c我不能完全做到这一点,但是我决定使用SQLBULK复制
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.