views:

174

answers:

1

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?

+1  A: 

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.

Mauricio Scheffer
Thanks, Mauricio!
Alex
I tried to increase timeout time (from 1000 to 10000) and decreased batch size (from 1000 to 100), now I get exception NHibernate.TransactionException: Transaction not connected, or was disconnected on quite random place of my batch operations. Why?
Alex
Hm... I get timeout exception once more what is impossible for such long timeout value. One of my friends said me that Nhibernate TransactionScope I am using do not use custom timeout. Do you know any workaround to populate timeout from config file to TransactionScope?
Alex
@Alex: please post another question.
Mauricio Scheffer
Posted: http://stackoverflow.com/questions/3855315/timeout-exception-when-using-nhibernate-transactionscope
Alex