timeout - NHibernate command_timeout does not work with batches -
today experienced issue timeouts.
i have following configuration used create sessionfactory:
<property name="adonet.batch_size">50</property> <property name="command_timeout">600</property>
i not store in web.config in xml file manually passed configuration:
configuration.configure(cfgfile)
thus can have multiple session factories (per database) independent configurations.
but command_timeout
seems effective when nhibernate not using batches. if sql commands batched large batches get:
nhibernate.exceptions.genericadoexception: not execute batch command. [sql: sql not available] ---> system.data.sqlclient.sqlexception: timeout expired. timeout period elapsed prior completion of operation or server not responding.
while googling solution, found article explains why happening: http://ronaldrosiernet.azurewebsites.net/blog/2013/04/20/timeout_in_nhibernate_batched_sessions
the cause of problem sql batching nhibernate using cfg.environment.commandtimeout instead of command_timeout
passed configuration when creating session.
i found way implement workaround when creating configuration:
if (configuration.properties.containskey(nhibernate.cfg.environment.commandtimeout)) nhibernate.cfg.environment.properties[nhibernate.cfg.environment.commandtimeout] = configuration.properties[nhibernate.cfg.environment.commandtimeout];
and colleagues timeout seems fixed now.
but confuses me following thread: https://forum.hibernate.org/viewtopic.php?f=25&t=983105
which says:
the property nhibernate.cfg.environment.properties returns copy of global properties, cannot modify it.
if nhibernate.cfg.environment.properties read-only copy, why workaround seems working fine? stable or maybe fix unreliable , might break in other cases?
and found related issue in nhibernate jira: https://nhibernate.jira.com/browse/nh-2153
if fixed issues command_timeout in v3.1.0., why still have use workaround in nhibernate v3.3.2. ?
does have insight on this?
i had same issue when using batches. nhibernate class sqlclientbatchingbatcher using command timeout environment.globalproperties read only. found 2 ways set timeout on sqlclientbatchingbatcher.currentbatch command
1) use timeout in app.config file
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="command_timeout">120</property> </session-factory> </hibernate-configuration>
2) set environment.
fieldinfo field = typeof(global::nhibernate.cfg.environment).getfield("globalproperties", system.reflection.bindingflags.nonpublic | system.reflection.bindingflags.static); dictionary<string, string> gloablproperties = field.getvalue(null) dictionary<string, string>; gloablproperties.add("command_timeout","120");
Comments
Post a Comment