.net 事务超时时间 10分钟?



写了一段程序,使用.net framework里的事务,设置了超时时间为30分钟,但是奇怪的是在10分钟的时候就报错了。搜索了一下,原来还需要修改machine.config(默认应该在C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG中),比如设置为30分钟:

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


需要注意的是,system.transactions应该放在configSections节点之后,否则程序启动时会报“无法识别的配置节 system.transactions”。


引用原文:

This came up a couple of times recently, so I am posting it more broadly. Courtesy of Mike Clark and Jim Carley. 

System.Transactions has two timeout values that you can specify in configuration files. 

The default timeout for System.Transactions transactions is 1 minute.  You can set it in either app config, web config, or machine config.  (You can also set the timeout for a particular transaction programmatically within the application, by using one of the appropriate constructors forTransactionScope or CommittableTransaction).  Setting the default timeout to 30 seconds in config code looks like the following.

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

For System.Transactions there is also a maximum transaction timeout. It is designed to be used by the System Administrator to limit transaction timeouts. If this setting is not specified, it defaults to 10 minutes.  It cannot be overridden in code.   If the app.config timeout or the timeout specified in the constructors above exceed the maximum timeout in the machine.config, the timeout is adjusted down to the maximum timeout value. That can be specified only in machine config.  To change that you would specify the maxTimeout property of the machine settings section.  For example, this specifies 30 seconds:

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

So, for example if your app.config setting specifies a defaultSettings timeout of zero, which implies (with a screwy sort of logic) infinite timeout, or if your application code specifies a zero timeout in one of the constructors, then the actual timeout of the transaction will not be infinite - it will be bound to the setting for machineSettings maxTimeout. 

For any high-throughput transactional server, The default maxTimeout setting is probably not right for you.  You're going to want to set this pretty low. 

This is for any transaction managed by DTC - that would include transactions involving SQL Server, Oracle, MQ, DB2, and so on.  If your transactions are timing out after 10 minutes and you want to know why, check these settings. 




原文地址:http://blogs.msdn.com/b/dotnetinterop/archive/2005/12/16/504604.aspx

1. .NET Core的优势与特点: - 跨平台:可以在Windows、Linux、macOS等操作系统上运行。 - 开放源代码:.NET Core是开源的,可在GitHub上查看和贡献代码。 - 高性能:.NET Core采用了新的运行时和优化技术,能够提供更快的执行速度。 - 简化开发:.NET Core提供了很多常用的API和工具,使得应用程序的开发变得更加简单。 - 模块化:.NET Core可以根据需要选择和加载所需的模块,减少不必要的依赖。 2. 对于C#中的委托(Delegate)的了解: 委托是一种类型安全的函数指针,它可以将一个或多个方法封装成一个委托实例,然后将该实例传递给其他方法作为参数或存储在变量中,从而实现方法的回调。 3. MVC架构模式的组件: - Model:模型层,用于表示应用程序的数据和业务逻辑。 - View:视图层,用于展示数据和与用户交互。 - Controller:控制器层,用于接收用户请求并处理它们,然后调度适当的模型和视图来响应请求。 4. 对于.NET中的反射机制(Reflection)的了解: 反射机制是指在运行时动态地获取和操作程序元素的能力,如类型、方法、属性、字段等。它可以用来实现很多高级功能,如动态加载程序集、创建对象、调用方法、获取属性等。 5. 数据库事务(Transaction)的理解和使用注意事项: 事务是一组相关的数据库操作,要么全部执行成功,要么全部回滚。它可以保证数据的一致性和可靠性。使用事务时需要注意以下几点: - 事务应该尽量的短。 - 事务中的操作应该尽量简单,避免复杂的逻辑。 - 在事务中应该尽量使用索引,避免锁表。 - 对于长时间运行的事务,应该考虑设置超时时间。 6. 对于SignalR的使用经验: SignalR是一种实时通信库,可以使得服务器端和客户端之间的通信更加简单和高效。在项目中,可以使用SignalR实现实时聊天、通知、在线用户列表等功能。通常使用Hub来处理客户端和服务器之间的通信。 7. 对于MongoDB的使用经验: MongoDB是一种文档型数据库,可以存储和查询JSON格式的数据。在使用MongoDB时,需要先创建数据库和集合,然后可以使用C#的驱动程序来进行数据的增删改查等操作。在项目中,可以使用MongoDB来存储用户信息、日志、配置等数据。 8. 对于异步编程(Async Programming)的了解和实现方式: 异步编程是指通过异步操作来提高程序的响应性和性能。在.NET中,可以使用async和await关键字来实现异步编程,从而避免线程阻塞和提高程序的吞吐量。 9. 对于.NET中的依赖注入(Dependency Injection)的了解和使用方式: 依赖注入是一种通过构造函数、属性或方法参数来注入依赖项的技术,可以提高代码的可测试性和可维护性。在.NET中,可以使用DI容器来管理依赖项,如ASP.NET Core中的内置DI容器或第三方的Autofac、Ninject等。 10. 对于.NET中的LINQ的了解和使用方式: LINQ是一种语言集成查询(Language Integrated Query)技术,可以通过类似于SQL的语法来查询各种数据源,如集合、数组、XML、数据库等。在.NET中,可以使用LINQ来进行数据过滤、排序、分组、投影等操作,从而简化代码并提高开发效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值