tags:

views:

61

answers:

2

If my application spans multiple databases, i.e. users 1-10K on server1, 10-10K on server2 (for example), how can I modify my session object to point the correct database?

From what I understand, if I change the connection string in nhibernate's session it will effect everyone and not the current request correct?

+2  A: 

In NHibernate it's the ISessionFactory which is responsible to hold connection string to a specific database and create ISession instances. For multiple database support you may take a look at NHibernate Shards which is still work in progress.

Darin Dimitrov
wonder if hibernate is more mature in this regards?
mrblah
Yes, `Hibernate Shards` is a more mature project.
Darin Dimitrov
A: 

You can only have one connection at a time in one session. To have more would lead to distributed or even ad-hoc transaction semantics, which NHibernate in its basic form doesn't support.

If you're using NHibernate, you're probably using SQL Server, and this sounds like the perfect candidate for linked servers and views. You could have one "main" database with views that consolidate data from all of the different databases. In fact, this is a pretty standard approach to table partitioning, the only difference being that your base tables are in different databases.

Aaronaught