我们的团队遇到了一个问题,表现为:
基础提供程序在EnlistTransaction上失败;无法访问已释放的object.Object名称:“Transaction”。

当我们开始使用TransactionScope来处理应用程序的事务时,它似乎就出现了。
堆栈跟踪的顶部被捕获为:
(在System.Data.EntityClient.EntityConnection.EnlistTransaction(Transaction事务)在System.Data.Objects.ObjectContext.EnsureConnection() at System.Data.Objects.ObjectContext.ExecuteStoreCommand(String命令文本,在Reconciliation.Models.BillLines.BillLines.Reconciliation.Interfaces.IBillLineEntities.ExecuteStoreCommand(String,Object[](在Reconciliation.Models.BillLines.BillLines.Reconciliation.Interfaces.IBillLineEntities.ExecuteStoreCommand(String,Object[]),在EntityDbEnvironment.cs中(第41行)
同时更新MSDTC日志,我使用这里的说明提取该日志
pid=7060 ;tid=7908 ;time=04/29/2013-16:38:30.269 ;seq=136 ;eventid=TRANSACTION_BEGUN ;tx_guid=60f6390c-7570-488a-97a9-2c3912c4ca3e ;"TM Identifier='(null) '" ;"transaction has begun, description :'<NULL>'"
pid=7060 ;tid=7908 ;time=04/29/2013-16:38:30.269 ;seq=137 ;eventid=RM_ENLISTED_IN_TRANSACTION ;tx_guid=60f6390c-7570-488a-97a9-2c3912c4ca3e ;"TM Identifier='(null) '" ;"resource manager #1002 enlisted as transaction enlistment #1. RM guid = 'defc4277-47a6-4cd9-b092-93a668e2097b'"
pid=7060 ;tid=7908 ;time=04/29/2013-16:38:31.658 ;seq=138 ;eventid=RECEIVED_ABORT_REQUEST_FROM_BEGINNER ;tx_guid=60f6390c-7570-488a-97a9-2c3912c4ca3e ;"TM Identifier='(null) '" ;"received request to abort the transaction from beginner"
pid=7060 ;tid=7908 ;time=04/29/2013-16:38:31.658 ;seq=139 ;eventid=TRANSACTION_ABORTING ;tx_guid=60f6390c-7570-488a-97a9-2c3912c4ca3e ;"TM Identifier='(null) '" ;"transaction is aborting"
pid=7060 ;tid=7908 ;time=04/29/2013-16:38:31.658 ;seq=140 ;eventid=RM_ISSUED_ABORT ;tx_guid=60f6390c-7570-488a-97a9-2c3912c4ca3e ;"TM Identifier='(null) '" ;"abort request issued to resource manager #1002 for transaction enlistment #1"
pid=7060 ;tid=7908 ;time=04/29/2013-16:38:31.658 ;seq=141 ;eventid=RM_ACKNOWLEDGED_ABORT ;tx_guid=60f6390c-7570-488a-97a9-2c3912c4ca3e ;"TM Identifier='(null) '" ;"received acknowledgement of abort request from the resource manager #1002 for transaction enlistment #1"
pid=7060 ;tid=7908 ;time=04/29/2013-16:38:31.658 ;seq=142 ;eventid=TRANSACTION_ABORTED ;tx_guid=60f6390c-7570-488a-97a9-2c3912c4ca3e ;"TM Identifier='(null) '" ;"transaction has been aborted"如您所见,在RECEIVED_ABORT_REQUEST_FROM_BEGINNER被记录后的第一秒就会看到一个RM_ENLISTED_IN_TRANSACTION。
我们无法理解这个中止请求是从哪里来的,也不知道为什么会引发这个请求。导致问题的SQL是一个简单的选择,我们可以通过我们的数据库客户端执行它而不发出任何问题。
应用程序大部分时间都能工作,只是偶尔显示这个问题。
我们在实体框架中使用Oracle 10.2.0.5.0。
更新
根据@Astrotrain的建议,我在System.Transactions上设置了日志记录。但是,最后一条条目实际上是半途而废:
....
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information">
<TraceIdentifier>http://msdn.microsoft.com/2004/06/System/Transactions/TransactionScopeCreated</TraceIdentifier>
<Description>TransactionScope Created</Description>
<AppDomain>BillLineGeneratorUI.exe</AppDomain>
<ExtendedData xmlns="http://schemas.microsoft.com/2004/03/Transactions/TransactionScopeCreatedTraceRecord">
<TraceSource>[Base]如您所见,异常实际上阻止了日志的完成。我能从中学到什么?有什么想法吗?
发布于 2014-07-14 18:58:58
我可以建议使用System.Transactions跟踪源,而不是使用MSDTC跟踪工具(我发现这个工具非常简陋)--只需在web.config中包含以下内容:
如果您用SvcTraceViewer.exe打开日志文件,您将得到这些步骤的良好的可视化表示。
<configuration>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.Transactions" switchValue="Information">
<listeners>
<add name="tx"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\MyApp-transactions-log.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>这本身并不是一个解决方案,但这可能会给您提供更多关于哪里出了问题的信息。
发布于 2013-06-06 08:48:17
我们也有这个问题。解决这个问题的最好方法似乎是打开一个新的数据库连接,只需完成事务中所需的事情。尽可能少的交易总是好的。
DatabaseContext db1 = new DatabaseContext();
doSomeDatabaseActions(db1);
TransactionOptions transOpts = new TransactionOptions();
transOpts.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, transOpts))
{
using (DatabaseContext db2 = new DatabaseContext())
{
doDatabaseChecksWithLock(db2);
doChanges(db2);
db2.SaveChanges();
}
scope.Complete();
}我们在没有引入第二个连接的情况下遇到了问题。请注意,如果扩大了事务(使doSomeDatabaseActions成为事务的一部分),则使用1连接(DoSomeDatabaseActions)也会消除错误。
发布于 2014-07-16 09:55:56
正如您提到的,“应用程序大部分时间都能工作,只是偶尔显示这个问题。”由此我们可以得出结论,提供者确实支持分布式事务,其原因是连接或处理上的其他间歇性故障。
https://stackoverflow.com/questions/16283524
复制相似问题