NHibernate uses one config file to connect to multiple dbs
I would like to have a single config file and then when I create a session change the hibernate-configuration-> session- factory property -> connection.connection_string for what I want it to be programmatic? Is it possible?
UPDATE:
I believe I can do it like this
Configuration cfg = new Configuration();
cfg.Configure(sessionFactoryConfigPath);
cfg.Properties["connection.connection_string"] = ...
What I would be wondering if this was ok is a bad way to deal with connecting to a different database for each session? if so why, etc. I would also like to know if it is possible / how to open an nhibernate session using a .net connection object?
source to share
Use the ISessionFactory.OpenSession()
overload that takesIDbConnection
.
That the Castle isDifferentDatabaseScope
doing it.
source to share
You can also see this answer as it allows you to completely configure the session factories through a single file. Customize NHibernate hibernate.cfg.xml file to have more connection strings
source to share