title: Changing NHibernate Session.Save command timeout
body: <p>We have a couple of long running back-end processes that take longer than the default 30 seconds.</p>
  
  <p>Our NHibernate version is 2.0.1.4000 and Spring.NET is 1.2.0.20313.
  NHibernate is configured through Spring.NET this way:</p>
  
  <pre><code>&lt;object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate20"&gt;
      &lt;property name="DbProvider" ref="DbProvider"/&gt; 
      &lt;property name="MappingAssemblies"&gt;
          &lt;list&gt;
              &lt;value&gt;SomeKindOfAnItem&lt;/value&gt;
          &lt;/list&gt; 
      &lt;/property&gt;
      &lt;property name="HibernateProperties"&gt;
          &lt;dictionary&gt;
              &lt;entry key="expiration" value="120"/&gt;
              &lt;entry key="adonet.batch_size" value="10"/&gt;
              &lt;entry key="cache.provider_class" value="NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache"/&gt;
              &lt;entry key="cache.use_query_cache" value="true"/&gt;
              &lt;entry key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/&gt;
              &lt;entry key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/&gt;
              &lt;entry key="dialect" value="NHibernate.Dialect.MsSql2005Dialect"/&gt;
              &lt;entry key="current_session_context_class" value="Spring.Data.NHibernate.SpringSessionContext, Spring.Data.NHibernate20"/&gt;
              &lt;entry key="show_sql" value="false"/&gt;
          &lt;/dictionary&gt;
      &lt;/property&gt;
  &lt;/object&gt;
  </code></pre>
  
  <p>To get around this, I am trying to set the NHibernate command_timeout to 60 in the Web.config.
  This is from Web.config:</p>
  
  <pre><code>&lt;hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"&gt;
    &lt;session-factory&gt;
      &lt;property name="command_timeout"&gt;60&lt;/property&gt;
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Unfortunately this does not work, the command times out after 30 seconds.</p>
  
  <p>I built a console app that calls the DAO just like the web app does it. I have the exact same NHibernate configuration setting in its configuration file. The IDbCommand times out after 60 seconds and not 30, using the setting successfully from the config file.</p>
  
  <p>I tried debugging the app and check if the commandTimeout was set when the DAO assembly is called from the web site. It was.</p>
  
  <p>This is from Visual Studio watch:</p>
  
  <blockquote>
    <p>((NHibernate.Driver.DriverBase)(((NHibernate.Connection.DriverConnectionProvider)
    ((NHibernate.Impl.SessionFactoryImpl)session.SessionFactory)
     .ConnectionProvider).Driver)).commandTimeout: 60</p>
  </blockquote>
  
  <p>The session is created like this:</p>
  
  <pre><code>ISession session = SessionFactoryUtils.GetSession(HibernateTemplate.SessionFactory, true);
  </code></pre>
  
  <p>My question is: if the command timeout field was successfully set to 60 from my Web.config, why does it time out after 30 seconds? Any ideas I could try?</p>