我正在创建一种将大量新记录批量插入(导入)到 ORACLE 数据库中的机制。我正在使用多个线程和依赖事务:
线程的创建:
const int ThreadCount = 4;
using (TransactionScope transaction = new TransactionScope())
{
List<Thread> threads = new List<Thread>(threadCount);
for (int i = 0; i < ThreadCount; i++)
{
Thread thread = new Thread(WorkerThread);
thread.Start(Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete));
threads.Add(thread);
}
threads.ForEach(thread => thread.Join());
transaction.Complete();
}
执行实际工作的方法:
private void WorkerThread(object transaction)
{
using (DependentTransaction dTx = (DependentTransaction)transaction)
using (TransactionScope ts = new TransactionScope(dTx))
{
// The actual work, the inserts on the database, are executed here.
}
}
System.Data.OracleClient.OracleException
在此操作期间,我收到message类型的异常ORA-24757: duplicate transaction identifier
。
我究竟做错了什么?我是否以不正确的方式执行依赖事务?它与Oracle不兼容吗?如果是这样,是否有解决方法?