Sure you can. Seems like you were already on one possible way in your
first mail. Either use multiple configuration files, one for each
session-factory, or just define all the connection string in
app/web.config using the normal <connectionstrings> clause. Then use
programmatic configuration of your sessionfactories. Plus a way for a
"sessionfactory consumer" to find the right one.

/Oskar


2010/1/20 csetzkorn <[email protected]>:
> Hi,
>
> I had a quick look at this. It all seems very complicated and my
> requirement may be different to what you refer to. Sorry if I am not
> clear enough. Looking for example at:
>
> NHibernateSession.IsConfiguredForMultipleDatabases
>
> My web applications has a few sets of pages. Each set manipulates a
> different database so needs to run (?) NHibernate separately - i.e.
> having its own instance - hope that's the right terminology.
>
> In the past I have used EF and/or plain old ADO.NET/C# to achieve
> this. It was just a question of defining several connection strings.
> This should be possible as well or can I only run one 'instance' ???
> of NHibernate to access several databases.
>
> Thanks.
>
> Best wishes,
>
> Christian
>
>
> On Jan 19, 7:28 pm, devonl <[email protected]> wrote:
>> Essentially, you'll need to set up a collection in the web application
>> that stores each configured session for NH. Then you'll instantiate a
>> session for each database. Check out S#arp Archtiecture for a nice way
>> to accomplish this. IN Billy's example, he uses a Dictionary of
>> strings and ISession objects, then grabs the appropriate session
>> object based on the key:
>>
>> http://github.com/codai/Sharp-Architecture/tree/master/src/SharpArch/...
>>
>> hth,
>>
>> -devon
>>
>> On Jan 19, 8: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.
>
>
>
>
-- 
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