Monday, February 18, 2013

NHibernate: change command timeout

Every query you execute in NHibernate has a default timeout value. This timeout is set on every IDbCommands generated by NHibernate. Most of the time the default value is just fine, but sometimes you have this annoying query that just takes a little bit too much time.

You have multiple options to change the timeout value.

Global change

If you want to change it for all queries in your application, you can configure the following value in your NHibernate configuration:

  • command_timeout: Specify the default timeout of IDbCommands generated by NHibernate.
Local change

If you only want to change this for a specific query, you can set it using the SetTimeout method on ICriteria:

or on QueryOver:

No comments: