问题
I am trying to batch insert 100k+ items to my Oracle db using ADO.NET inside a TransactionScope. Like this:
using (TransactionScope transaction = new TransactionScope())
{
while(/* Pagination logic - send insertion command on every 250 items */)
{
using (OracleCommand command = new OracleCommand(query, connection))
{
command.ArrayBindCount = 250;
//Add parameters
command.Parameters.Add(":BLAH", OracleDbType.Long);
command.Parameters[0].Value = LUC.ToArray();
command.ExecuteNonQuery(); //Error occurs here after N-times inside while
}
}
transaction.Complete();
}
For items lower than this (10k-30k) transaction is completed successfully. However for higher items (like 100k) I get ORA-00604: error occurred at recursive SQL level %s.
If I remove TransactionScope altogether, I don't get any error with any item size, it just works.
How can I make TransactionScope work with huge number of items?
回答1:
Turns out, it was a transactional timeout problem.
After I increased the timeout, I have inserted my list successfully:
using (TransactionScope transaction =
new TransactionScope(TransactionScopeOption.Required,
new TimeSpan(0, 30, 0))) //30 minute timeout limit
来源:https://stackoverflow.com/questions/33517597/ora-00604-error-while-batch-insertion-inside-transactionscope