3
votes

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>

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

Somewhere at the beginning:

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

Somewhere at the end:

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)

How come? How to fix this?

2
this a web application I'm assuming? - hardba11
Sorry, did not state this. No, this is regular desktop application. - Alex
Are you using batching (adonet.batch_size > 0) ? Why do you have an ActiveRecord configuration and a separate NHibernate configuration? What kind of SQL statement is timing out (update/insert/select/delete)? What version of NHibernate and ActiveRecord are you using? - Mauricio Scheffer
@Mauricio: Yes, I am using batch_size=1000. I have two configurations because in the past I met situations when one key works being defined in ActiveRecord section while another works only for Nhibernate so I decided to have both (maybe this is wrong). The statement is insert, batch insert. Nhibernate is 2.1.2.4000 and CastleProject is 2.1.0.6692. - Alex
I have a theory... try setting batch_size to 0, and see if it still times out. Please post back here with the result. - Mauricio Scheffer

2 Answers

5
votes

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.

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.

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.

Please confirm this with NHibernate devs.

0
votes

You might be looking to set the timeout for specific queries and not at web.config level (otherwise you really need to tune up your application :) ).

I've recently found this answer that helped me:

How to set Nhibernate LINQ Command Timeout using Session.Query