How do you change NHibernate's connection string per HTTP request?

An ISessionFactory.OpenSession() can be supplied with a IDbConnection.

Another option is to implement a IConnectionProvider wich would create appropriate IDbConnection instances depending upon some condition (which has to be global, thus rendering this solution not very clean).


Note that when supplying an IDbConnection to OpenSession(), you will not be able to use the 2nd level cache.

See https://forum.hibernate.org/viewtopic.php?f=25&t=959178

... "This is not a bug. If you are managing your own connections, NHibernate disables the use of second-level cache for the session to be safe."...