如果machine.config上没有“system.transactions”元素,则maxTimeout的machine.config中的默认值是什么(参见示例)?
<system.transactions> <machinesettings maxTimeout="??:??:??" /> </system.transactions>
我问这个是因为代码因以下异常而崩溃,似乎它与超时超时的事务有关,它在SaveChanges方法期间崩溃,我收到的异常如下:
The transaction associated with the current connection has completed but has not been disposed. The transaction must be disposed before the connection can be used to execute sql statements.
这是崩溃的代码片段:
using (TransactionScope transaction = TransactionHelper.CreateTransactionScope()) { using (EFContext efdbContext = new EFContext()) { try { efdbContext.Connection.open(); foreach (MyEntity currentEntity in myEntities) { //Insertion } transaction.Complete(); } catch (Exception ex) { //Inspect current entity //Get Total Time of the run //Number of entities processed } finally { if (esfdbContext.Connection.State == ConnectionState.Open) esfdbContext.Connection.Close(); } } }
public static TransactionScope CreateTransactionScope(TransactionScopeOption option = TransactionScopeOption.required,IsolationLevel isolationLevel = IsolationLevel.ReadCommitted) { var transactionoptions = new Transactionoptions() { Timeout = TimeSpan.MaxValue,IsolationLevel = isolationLevel }; return new TransactionScope(option,transactionoptions); }
解决方法
原文地址:https://www.jb51.cc/mssql/77452.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。