0
votes

I want to use two connection strings of two different sql database but my problem is nhibernate allows one connection string for one session under one sessionFactory. If I want to use second connection string for different session and also these two database insert operations maintain under one transaction. So how it possible using nhibernate.

1
You should use two session factories and transaction scopes. Why do you have that requirement of a single session factory? Otherwise see there for a way to use a single session factory, but you really should consider using two. - Frédéric

1 Answers

0
votes

If the databases are on the same sql server which it sounds like they are, this is possible by specifying the schema in your mappings. No need for multiple sessions.

public class PersonMap : ClassMap<Person>
{
  public PersonMap()
  {
    Schema("MyOtherDatabase.dbo");
  }
}

This will get appended to your NHibernate queries wherever Person is referenced.

For old school hibernate style mapping see: 5.1.2. hibernate-mapping in http://nhibernate.info/doc/nhibernate-reference/mapping.html