【发布时间】:2012-01-10 18:14:47
【问题描述】:
关于以下错误的任何想法:
System.Data.EntityException: An error occurred while starting a transaction on the provider connection. See the inner exception for details. ---> System.ObjectDisposedException: Safe handle has been closed
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
at SNINativeMethodWrapper.SNIPacketReset(SafeHandle pConn, IOType ioType, SafeHandle packet)
at System.Data.SqlClient.TdsParserStateObject.WriteSni()
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.SqlInternalConnection.BeginSqlTransaction(IsolationLevel iso, String transactionName)
at System.Data.SqlClient.SqlInternalConnection.BeginTransaction(IsolationLevel iso)
at System.Data.SqlClient.SqlConnection.BeginDbTransaction(IsolationLevel isolationLevel)
at System.Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel)
--- End of inner exception stack trace ---
at System.Data.EntityClient.EntityConnection.BeginDbTransaction(IsolationLevel isolationLevel)
at System.Data.EntityClient.EntityConnection.BeginTransaction()
at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave)
为了给您一些背景知识,我们在应用程序的这一部分使用纯 ADO.NET(无事务),它运行良好。我们切换到 EF 后,开始收到此错误。我不相信这与 EF 相关,因为它发生在 ADO.NET 事务代码的深处。有什么方法可以禁用 EF 中的事务?
【问题讨论】:
-
您应该重新使用纯 ADO.NET 和宫内节育器。 :)
-
哈哈,谢谢,杰。这非常令人鼓舞。
-
如果有人有兴趣,没有办法在 EF 中禁用事务。如果您不指定一个,它将在 SaveChanges 调用期间为您创建一个默认值。
标签: .net entity-framework-4 transactions