我在基于 Silverlight 和 RIA 服务的项目中使用 TransactionScope 类。每次我需要保存一些数据时,我都会创建一个 TransactionScope 对象,使用 Oracle ODP 保存我的数据,然后在我的 TransactionScope 对象上调用 Complete 方法并处理对象本身:
public override bool Submit(ChangeSet changeSet)
{
TransactionOptions txopt = new TransactionOptions();
txopt.IsolationLevel = IsolationLevel.ReadCommitted;
using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required, txopt))
{
// Here I open an Oracle connection and fetch some data
GetSomeData();
// This is where I persist my data
result = base.Submit(changeSet);
tx.Complete();
}
return result;
}
我的问题是,第一次调用 Submit 方法时,一切都很好,但是如果我第二次调用它,执行会在调用 Complete 后卡住几分钟(因此,在处理 tx 时) ,然后我收到 Oracle 错误“ORA-12154”。当然,我已经检查了我的持久性代码是否完整无误。有任何想法吗?
编辑:今天我重复了测试,由于某种原因,我得到了一个不同的错误,而不是 Oracle 异常:
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at System.Transactions.TransactionState.ChangeStatePromotedAborted(InternalTransaction tx)
at System.Transactions.InternalTransaction.DistributedTransactionOutcome(InternalTransaction tx, TransactionStatus status)
at System.Transactions.Oletx.RealOletxTransaction.FireOutcome(TransactionStatus statusArg)
at System.Transactions.Oletx.OutcomeEnlistment.InvokeOutcomeFunction(TransactionStatus status)
at System.Transactions.Oletx.OletxTransactionManager.ShimNotificationCallback(Object state, Boolean timeout)
at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object state, Boolean timedOut)