超时设置为无限时间时发生超时异常 [英] Timeout exception when timeout set to infinite time

查看:305
本文介绍了超时设置为无限时间时发生超时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的C#.NET 3.5应用程序中,我正在NHibernate上使用CastleProject ActiveRecord.这是使用MS SQL Server 2008的桌面应用程序.我已将ADO命令超时设置为0,以防止批量操作期间发生超时异常:

In my C# .NET 3.5 application I am using CastleProject ActiveRecord over NHibernate. This is desktop application using MS SQL Server 2008. I have set ADO command timeout to 0 to prevent timeout exception during bulk operations:

  <activerecord>
    <config>
      ...
      <add key="hibernate.command_timeout" value="0" />
    </config>
  </activerecord>

  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      ...
      <property name="command_timeout">0</property>
    </session-factory>
  </hibernate-configuration>

但是,我仍然收到超时异常! NHibernate日志显示如下内容:

However, I am still receiving timeout exception! The NHibernate log shows something like this:

开头的某个地方:

2010-10-02 06:29:47,746信息 NHibernate.Driver.DriverBase-将ADO.NET命令超时设置为0秒

2010-10-02 06:29:47,746 INFO NHibernate.Driver.DriverBase - setting ADO.NET command timeout to 0 seconds

末尾某处:

2010-10-02 07:36:03,020调试 NHibernate.AdoNet.AbstractBatcher- 关闭IDbCommand,打开IDbCommand: 0 2010-10-02 07:36:03,382错误 NHibernate.Event.Default.AbstractFlushingEventListener -无法与会话同步数据库状态 NHibernate.HibernateException:一个 执行时发生异常 批处理查询---> System.Data.S qlClient.SqlException:超时 已到期.超时时间已过 在操作完成之前 或服务器没有响应.在 System.Data.SqlClient.SqlConnection.OnError(SqlException 例外,布尔值breakConnection)

2010-10-02 07:36:03,020 DEBUG NHibernate.AdoNet.AbstractBatcher - Closed IDbCommand, open IDbCommand s: 0 2010-10-02 07:36:03,382 ERROR NHibernate.Event.Default.AbstractFlushingEventListener - Could not syn chronize database state with session NHibernate.HibernateException: An exception occurred when executing batch queries ---> System.Data.S qlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the opera tion or the server is not responding. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

为什么?该如何解决?

推荐答案

值为0表示没有超时是正确的(如 NHibernate的驱动程序将配置值> = 0传递给db命令,则批处理程序的条件检查该值是否> 0 .

It's correct that a value of 0 indicates no timeout (as defined in the MSDN docs), however while NHibernate's driver passes the config value to the db command when it's >= 0, the batcher's condition checks that the value is > 0.

因此,当您设置批处理时,如果超时值为0,则该值不会传递到db命令,因此它将保留为默认值.

Therefore, when you set batching on, with a timeout value of 0, the value isn't carried over to the db command so it remains as default.

这完全有可能是设计使然,NHibernate开发人员有意禁用了批处理方案的禁用超时功能.无论如何,禁用超时都是一个坏主意,如果您遇到超时错误的麻烦,我会提高该值,但不会禁用它.

It's entirely possible that this is by design, and that NHibernate developers intentionally disabled disabling timeouts for batch scenarios. Disabling timeout is a bad idea anyway, if you have troubles with timeout errors I would raise the value, but not disable it.

请与NHibernate开发人员确认.

Please confirm this with NHibernate devs.

这篇关于超时设置为无限时间时发生超时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆