在我的 C# .NET 3.5 应用程序中,我在 NHibernate 上使用 CaSTLeProject ActiveRecord。这是使用 MS SQL Server 2008 的桌面应用程序。我已将 ADO 命令超时设置为 0 以防止批量操作期间出现超时异常:
<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 日志显示如下内容:
开头的某处:
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 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 值表示没有超时是正确的(如 defined in the MSDN docs ),但是 NHibernate's driver passes the config value to the db command when it's >= 0 是正确的, batcher的情况checks that the value is > 0 .
因此,当您将批处理设置为开启时,超时值为 0,该值不会转移到 db 命令,因此它保持默认值。
这完全有可能是设计使然,NHibernate 开发人员有意禁用批处理场景的禁用超时。无论如何,禁用超时不是一个好主意,如果您遇到超时错误,我会提高该值,但不会禁用它。
请与 NHibernate 开发人员确认这一点。
关于nhibernate - 超时设置为无限时间时超时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3844327/