System.Transactions事务超时设置

System.Transactions 有2个超时属性(timeout 与 maxTimeout),可以通过配置文件来进行设置。

1. timeout

System.Transactions 默认的timeout值为1分钟,可以通过app.config/web.config/machine.config来进行设置(对于应用中具体的事务还可以通过调用具体对象TransactionScopeCommittableTransaction的构造函数进行设置)。以下配置样例代码将其设置为30秒:

<configuration>
 <system.transactions>
  <defaultSettings timeout="00:00:30" />
 </system.transactions>
</configuration>

2. maximum transaction timeout

System.Transactions此外还有一个属性: maximum transaction timeout,该属性主要是系统管理员用于限制事务超时,其默认值为10分钟,并且不可在代码中覆盖设置。如果在配置文件或者代码中所设置的超时值均已超出该值,则以该值为准。maximum transaction timeout只能在machine.config文件中进行配置,以下配置样例代码将其设置为30分钟:

<configuration>
 <system.transactions>
   <machineSettings maxTimeout="00:30:00" />
 </system.transactions>
</configuration>

综上所述,即使在应用的配置文件或代码中将timeout设置为0,试图将事务超时时间设置为无限长也是无效的,整个事务的实际超时时间还是为machineSetting的maxTimeout值所限制。

注:代码中设置非默认时这样写:

using (var scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 3, 0)))

TransactionScopeOption.Required为默认,主要为后面的时间参数

时间: 2024-08-18 02:30:43

System.Transactions事务超时设置的相关文章

System.Transactions 事务超时属性

System.Transactions 有2个超时属性(timeout 与 maxTimeout),可以通过配置文件来进行设置. 1. timeout System.Transactions 默认的timeout值为1分钟,可以通过app.config/web.config/machine.config来进行设置(对于应用中具体的事务还可以通过调用具体对象TransactionScope或CommittableTransaction的构造函数进行设置).以下配置样例代码将其设置为30秒: <co

谈谈分布式事务之三: System.Transactions事务详解[上篇]

在.NET 1.x中,我们基本是通过ADO.NET实现对不同数据库访问的事务..NET 2.0为了带来了全新的事务编程模式,由于所有事务组件或者类型均定义在System.Transactions程序集中的System.Transactions命名空间下,我们直接称基于此的事务为System.Transactions事务.System.Transactions事务编程模型使我们可以显式(通过System.Transactions.Transaction)或者隐式(基于System.Transact

谈谈分布式事务之三: System.Transactions事务详解[下篇]

在前面一篇给出的Transaction的定义中,信息的读者应该看到了一个叫做DepedentClone的方法.该方法对用于创建基于现有Transaction对 象的“依赖事务(DependentTransaction)”.不像可提交事务是一个独立的事务对象,依赖事务依附于现有的某个事务(可能是可提交事 务,也可能是依赖事务).依赖事务可以帮助我们很容易地编写一些事务型操作,当环境事务不存的时候,可以确保操作在一个独立的事务中执行:当环境事务存在 的时候,则自动加入其中. 一.依赖事务(Depen

C#高级编程 25.5 System.Transactions学习笔记

在.NET 1.x中,基本上是通过ADO.NET实现对不同数据库访问的事务..NET 2.0增加了System.Transactions名称空间,为.NET应用程序带来了一个新的事务变成模型. 所有的事务组件或者类型均定义在System.Transactions程序集中的System.Transactions命名空间下,我们直接称基于此的事务为System.Transactions事务. System.Transactions事务变成模型使我们可以显式(通过System.Transactions

你应该知道的那些超时设置或默认参数 good

defaultStatementTimeout Sets the number of seconds the driver will wait for a response from the database. Any positive integer Not Set (null) http://www.mybatis.org/mybatis-3/configuration.html 存储介质 Redis Java-Driver Jedis 连接池:Jedis的连接池设计基于 Apache Co

Spring事务超时时间可能存在的错误认识

摘自:http://jinnianshilongnian.iteye.com/blog/1986023, 感谢作者. 1.先看代码 1.1.spring-config.xml Java代码   <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName&q

Outlook Web App 客户端超时设置

这篇文章我们讨论一下,OWA 2013在公共和私人的电脑是如何启用和配置. Exchange 2013 Outlook Web App (OWA) 登录页不再允许用户选择无论他们正在使用公共的或私人的计算机.默认情况下,OWA 2013 是假定用户使用的是私人计算机,如使用超时的 8 小时.出于安全考虑,用户处于非活动状态之前要求用户重新登录. 在 Set-OWAVirtualDirectory cmdlet 中 LogonPagePublicPrivateSelectionEnabled 参数

MongoDB和System.Transactions

此文为译文,原文地址请点击. 如何在你的MongoDB操作使用TransactionScope? 简介MongoDB是一个开源的NoSQL面向文档的数据库,以JSON格式的动态数据模式,以上是维基百科的描述.这篇文章的目的并不是提供一个高水平的MongoDB 速成课程,但是如果你不知道MongoDB这款华丽的软件,产品网站本身是更好的起点https://www.mongodb.com/what-is-mongodb.本文档是不仅仅是作为一个C#使用MongoDB的例子,而且它是在一定程度上规范你

http超时设置

http协议中可以设置超时(连接超时.响应超时),具体设置情景如下: 1.java api的方式: JDK 1.5以前的版本,只能通过设置两个系统属性来控制网络超时: String szUrl = "http://www.ee2ee.com/"; URL url = new URL(szUrl); HttpURLConnection urlCon = (HttpURLConnection)url.openConnection(); //HttpURLConnection是基于HTTP协