TheBoubou
TheBoubou

Reputation: 19903

Set NHibernate database at runtime

Imagine, I have a website, this one offer a service. To access to this service, I need to enter login/password. I'd like depending of the login set the database to use. Example :

Is it possible to set at runtime the database to use with Nhibernate ?

Thanks,

Upvotes: 0

Views: 586

Answers (1)

Ken Chan
Ken Chan

Reputation: 90457

You can imagine that SessionFactory represents a database ,and Session represents a database connection. The Session is get from the SessionFactory ,just like you get the database connection from database. Given a Session , you cannot change the database that it connects to.

In your case, you should create the SessionFactory for both the database1 and database23 . Get the the Session from database1 's SessionFactory if you want to connect to database1 . Otherwise , get the Session from database23 's SessionFactory

Upvotes: 6

Related Questions