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

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

问题描述

我有一个方法,它使用实体框架在不同的实体中进行一些更改/插入,所有这些都在单个事务范围内.这些更改效果很好.

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() 之后,当 using 块关闭时抛出.

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

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

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