不能从事务范围内的Entity Framework调用存储过程? [英] Can't I call a stored procedure from Entity Framework inside a transaction scope?

查看:221
本文介绍了不能从事务范围内的Entity Framework调用存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用实体框架在不同实体中进行一些更改/插入的方法,所有这些都在单个事务范围内。这些变化非常好。

I have a method that uses Entity Framework to do some changes/inserts in different entities, all this inside a single transaction scope. These changes works very well.

当我需要在这些操作中使用存储过程时,我的问题已经开始了。该过程仅在一个表中插入,并且没有明确的事务声明。我已经尝试声明一个事务,并在那里提交,但问题是一样的。

My problem has began when I needed to use a stored procedure in the middle of these operations. The procedure does only an insert in one table, and has no explicit declaration of transactions. I've tried declaring a transaction and commiting there also, but the problem was the same.

我不能在一个实体框架(EF1)内调用一个存储过程事务范围?

Can't I call a stored procedure from Entity Framework (EF1) inside a transaction scope?

当使用块关闭时,这个异常仅在transaction.Complete()之后抛出。

This exception is thrown only after transaction.Complete(), when the using block is closed.

The transaction has aborted.

   at System.Transactions.TransactionStatePromotedAborted.PromotedTransactionOutcome(InternalTransaction tx)
   at System.Transactions.TransactionStatePromotedEnded.EndCommit(InternalTransaction tx)
   at System.Transactions.CommittableTransaction.Commit()
   at System.Transactions.TransactionScope.InternalDispose()
   at System.Transactions.TransactionScope.Dispose()

内部异常:

The transaction operation cannot be performed because there are pending requests working on this transaction.

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest, String name, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlDelegatedTransaction.SinglePhaseCommit(SinglePhaseEnlistment enlistment)

更新:开始赏金

今天我不再通过实体框架调用此过程。我通过ADO.net打电话给这个程序,这是我的解决方法。但问题仍然存在,我应该在不久的将来需要拨打一些电话,也许在一个交易范围内。

Today I'm not doing this procedure call through Entity Framework anymore. I'm calling the procedure through ADO.net, this was my workaround. But the problem continues, I should need make some calls in the near future, maybe inside a transaction scope.

推荐答案

一个hotifx? KB 936983

A bug with a hotifx? KB 936983

这篇关于不能从事务范围内的Entity Framework调用存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆