views:

44

answers:

1

Hi,

We have a situation where we have multiple databases with identical schema, but different data in each. We're creating a single session factory to handle this.

The problem is that we don't know which database we'll connect to until runtime, when we can provide that. But on startup to get the factory build, we need to connect to a database with that schema. We currently do this by creating the schema in an known location and using that, but we'd like to remove that requirement.

I haven't been able to find a way to create the session factory without specifying a connection. We don't expect to be able to use the OpenSession method with no parameters, and that's ok.

Any ideas? Thanks Andy

+1  A: 

Either implement your own IConnectionProvider or pass your own connection to ISessionFactory.OpenSession(IDbConnection) (but read the method's comments about connection tracking)

Mauricio Scheffer
Care to provide us with an example?
Rafael Belliard
Mauricio, thanks, I'll check into that. I had thought about your latter suggestion, but it wasn't clear from my research if NHibernate would close the connection or if we would take on the responsibility. I'll read up on the IConnectionProvider, it looks like that might be closer to what we need.
Andy