I do not have an answer but I do have the same question.  I am in the
process of evaluating moving my application to nhibernate and the
immediate question is does nhibernate support multiple databases.  I
have an applications where each client using it has a unique database,
so based on who is logged in we go to the appropriate database, thus a
different connection string per client.  Is this possible with
NHibernate?
Thanks

On Jan 19, 9:13 am, csetzkorn <[email protected]> wrote:
> Dear all,
>
> I am a bit stuck and would like some help please.
>
> I am using DAOs in a web application (ASP.NET MVC within controllers)
> served by two dao factories which access two separate databases.
>
> The DAOs use this class:
>
> public class NHibernateHelper
>     {
>         private static ISessionFactory sessionFactory;
>
>         public static ISessionFactory SessionFactory
>         {
>             get
>             {
>                 if (sessionFactory == null)
>                 {
>                     sessionFactory = new Configuration().Configure
> ().AddAssembly("Bla").BuildSessionFactory();
>                 }
>                 return sessionFactory;
>             }
>         }
>
>         public static ISession OpenSession()
>         {
>             return SessionFactory.OpenSession();
>         }
>
>         public static ISession GetCurrentSession()
>         {
>             if (!CurrentSessionContext.HasBind(SessionFactory))
>             {
>                 CurrentSessionContext.Bind(SessionFactory.OpenSession
> ());
>             }
>             return SessionFactory.GetCurrentSession();
>         }
>
>         public static void DisposeSession()
>         {
>             var session = GetCurrentSession();
>             session.Close();
>             session.Dispose();
>         }
>
>         public static void BeginTransaction()
>         {
>             GetCurrentSession().BeginTransaction();
>         }
>
>         public static void CommitTransaction()
>         {
>             var session = GetCurrentSession();
>             if (session.Transaction.IsActive)
>                 session.Transaction.Commit();
>         }
>
>         public static void RollbackTransaction()
>         {
>             var session = GetCurrentSession();
>             if (session.Transaction.IsActive)
>                 session.Transaction.Rollback();
>         }
>     }
>
> This is all no problem if I only use one database as I can just define
> one hibernate-configuration section in my Web.config. I am just
> wondering what I can do to define the connection strings for two or
> more databases. I could use something like this when the singleton
> sessionFactory is accessed:
>
> SessionFactory sf = new Configuration()
> .Configure("/path/to/config.cfg.xml")
> .BuildSessionFactory();
>
> or this:
>
> cfg.SetProperty("connection.connection_string",
> get_connection_string_from_other_web_config);
> cfg.BuildSessionFactory();
>
> However, this seems all a bit 'dirty' (I did not try it yet as well).
> I would also like to use my DAO classes etc. in other applications
> (e.g. console application). Any feedback would be very much
> appreciated. Many thanks in advance.
>
> Best wishes,
>
> Christian
-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.


Reply via email to