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?

+2


source to share


3 answers


+3


source


I think it is better to use different config files per database just because you will be able to switch dialects very esasy.



+2


source


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

0


source







All Articles