Since the connection string is the same, I think you should not try to use
the same connection and only leave managing connections to connection
pooling.

Quick relevant search results:
http://aspalliance.com/1099_Understanding_Connection_Pooling_in_NET.all
http://ondotnet.com/pub/a/dotnet/2004/02/09/connpool.html


Regards,

--
Mohamed Meligy
Senior Developer, Team Lead Backup (.Net Technologies - TDG - Applications
Injazat Data Systems
P.O. Box: 8230 Abu Dhabi, UAE.

Phone:  +971 2 6992700
Direct:   +971 2 4045385
Mobile:  +971 50 2623624, +971 55 2017 621

E-mail: [email protected]
Weblog: http://weblogs.asp.net/meligy


On Tue, Dec 15, 2009 at 6:46 PM, Oskar Berggren <[email protected]>wrote:

> It works until it explodes. :)
>
> But I suppose that actual results may and will vary depending on the
> usage pattern of ISession. In many cases you might have multiple
> threads running independently, each having their own ISession. In this
> case you definitely need to have separate dbconnections for each, to
> prevent concurrency issues (no different from any other
> non-thread-safe object). Maybe there are other reasons as well.
>
> To reverse the issue, why do you think that "use as few db connections
> as possible (ideally one db connection per process)" should be done in
> this matter? What is your usage pattern for the ISessions in your
> actual program? The ISession is normally fairly short-lived, and
> furthermore it doesn't actually "occupy" a dbconnection unless there
> is an actual transaction open.
>
> /Oskar
>
>
> 2009/12/15 DanV <[email protected]>:
> > Hi
> > I've been using NHibernate v. 2.0.1 for a year and I find it to be a
> > great ORM.
> >
> > Recently I found myself in the situation to manage my own db
> > connections and to use as less db connections as possible (ideally one
> > db connection per process).
> > I've made some tests where I open parallel ISessions providing the
> > same instance of my own IDbConnection to each session, load data,
> > change it and save it back to db and it works just fine.
> > Here is an example of my test:
> >
> >  System.Configuration.Configuration config =
> > System.Configuration.ConfigurationManager.OpenExeConfiguration
> > (System.Configuration.ConfigurationUserLevel.None);
> >            System.Configuration.ConnectionStringSettings sett =
> > System.Configuration.ConfigurationManager.ConnectionStrings[0];
> >
> >                conn = new SqlConnection(sett.ConnectionString);
> >            conn.Open();
> >
> >            ISession s1 = _sessFactory.OpenSession(conn);
> >            ISession s2 = _sessFactory.OpenSession(conn);
> >
> >            IList<Building> buildings = s2.CreateQuery("from
> > Building").List<Building>();
> >            IList<Item> items = s1.CreateQuery("from Item").List<Item>
> > ();
> >
> >            items[1].Name = "item21";
> >            using (ITransaction transaction = s1.BeginTransaction())
> >            {
> >                s1.Save(items[1]);
> >                transaction.Commit();
> >            }
> >
> >            buildings[0].Height = 10;
> >            using (ITransaction transaction = s2.BeginTransaction())
> >            {
> >                s2.Save(buildings[0]);
> >                transaction.Commit();
> >            }
> >
> > Nevertheless NHibernate reference advices against this practice but
> > unfortunatelly without giving a reason why.
> >
> > Can someone pls tell me what can possibly go wrong in a scenario like
> > this?
> >
> > Thanks a lot.
> >
> > --
> >
> > 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]<nhusers%[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]<nhusers%[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