.net – 在SQL中什么是默认的最大事务超时

前端之家收集整理的这篇文章主要介绍了.net – 在SQL中什么是默认的最大事务超时前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果machine.config上没有“system.transactions”元素,则maxTimeout的machine.config中的默认值是什么(参见示例)?
  1. <system.transactions>
  2. <machineSettings maxTimeout="??:??:??" />
  3. </system.transactions>

我问这个是因为代码因以下异常而崩溃,似乎它与超时超时的事务有关,它在SaveChanges方法期间崩溃,我收到的异常如下:

  1. The transaction associated with the current connection has completed
  2. but has not been disposed. The transaction must be disposed before
  3. the connection can be used to execute sql statements.

这是崩溃的代码片段:

  1. using (TransactionScope transaction = TransactionHelper.CreateTransactionScope())
  2. {
  3. using (EFContext efDBContext = new EFContext())
  4. {
  5. try
  6. {
  7. efDBContext.Connection.Open();
  8.  
  9. foreach (MyEntity currentEntity in myEntities)
  10. {
  11. //Insertion
  12. }
  13.  
  14. transaction.Complete();
  15. }
  16. catch (Exception ex)
  17. {
  18. //Inspect current entity
  19. //Get Total Time of the run
  20. //Number of entities processed
  21. }
  22. finally
  23. {
  24. if (esfDBContext.Connection.State == ConnectionState.Open)
  25. esfDBContext.Connection.Close();
  26. }
  27. }
  28. }

这是我创建TransactionScope的方法

  1. public static TransactionScope CreateTransactionScope(TransactionScopeOption option = TransactionScopeOption.required,IsolationLevel isolationLevel = IsolationLevel.ReadCommitted)
  2. {
  3. var transactionOptions = new TransactionOptions()
  4. {
  5. Timeout = TimeSpan.MaxValue,IsolationLevel = isolationLevel
  6. };
  7.  
  8. return new TransactionScope(option,transactionOptions);
  9. }

解决方法

默认= 10分钟.最大= Infinity

猜你在找的MsSQL相关文章