B
Bruce Whitehouse
Hoping someone can help with an optimisation query...
I'm looping through an array, doing thousands of inserts. At present for
every iteration of the loop I'm creating a new command object, and opening
and closing the connection object, something along the lines of....
For Each objAS400Data In arrAS400
objCommand = New OracleCommand(strPackageName, objConnection)
objCommand.CommandType = CommandType.StoredProcedure
objCommand.Parameters.Add(New OracleParameter("IN_PARAMETER_ID",
OracleType.Int32)).Direction = ParameterDirection.Input
objCommand.Parameters("IN_PARAMETER_ID").Value = objParameter.Value
Try
objConnection.Open()
boolReturn = objCommand.ExecuteNonQuery
If Not (objCommand.Parameters("out_errMsg").Value Is DBNull.Value)
Then
strError += CStr(objCommand.Parameters("out_errMsg").Value)
boolReturn = False
objConnection.close()
objCommand = Nothing
Exit For
End Try
objConnection.close()
objCommand = Nothing
Next
Whilst this all works, I can't help but get the feeling that instantiating
all these objects, and opening/closing the connection is slowing things
down. Is there a better, more efficient way of doing this?
regards,
Bruce
I'm looping through an array, doing thousands of inserts. At present for
every iteration of the loop I'm creating a new command object, and opening
and closing the connection object, something along the lines of....
For Each objAS400Data In arrAS400
objCommand = New OracleCommand(strPackageName, objConnection)
objCommand.CommandType = CommandType.StoredProcedure
objCommand.Parameters.Add(New OracleParameter("IN_PARAMETER_ID",
OracleType.Int32)).Direction = ParameterDirection.Input
objCommand.Parameters("IN_PARAMETER_ID").Value = objParameter.Value
Try
objConnection.Open()
boolReturn = objCommand.ExecuteNonQuery
If Not (objCommand.Parameters("out_errMsg").Value Is DBNull.Value)
Then
strError += CStr(objCommand.Parameters("out_errMsg").Value)
boolReturn = False
objConnection.close()
objCommand = Nothing
Exit For
End Try
objConnection.close()
objCommand = Nothing
Next
Whilst this all works, I can't help but get the feeling that instantiating
all these objects, and opening/closing the connection is slowing things
down. Is there a better, more efficient way of doing this?
regards,
Bruce