My understanding (and I would welcome being corrected) is that if you
open a new connection using the same connection string as an existing,
open connection then connection pooling kicks in. Which would mean that
you wouldn't be opening a new connection, rather using an existing one.
E.g.
- Open Connection_A and use it for something.
- Meanwhile Open Connection_B (which will actually use the same
connection as Open Connection_A).
- Close Connection_B - A is in use so it stays open
- Close Connection_A - no more connections in use so it closes properly
Now, if you are frequently opening and then closing just one connection,
I don't quite see how connection pooling can help. I've tried connecting
to Access (albeit with ADO 2.7 not ADO.NET) and noticed it's
significantly slower if you keep opening and reopening a connection
rather than keeping it open.
I haven't tested it yet with SQL Server (I shall tomorrow) but I have
been informed that when you connect to Oracle (again not .NET) the
server assigns resources to that connection. If you close and reopen
just one connection (i.e. avoiding pooling) you take up fresh resources
from the server since it doesn't tidy up instantly.
Again: this is my understanding. Someone please speak up if this is
nonsense.
db.guru wrote:
Well, the collection loading happens within the main object, which uses
a connection and a datareader to load its own data. I suppose I could
close the main object's datareader before loading each collection. (not
sure why I didn't consider that initially...).
So it's not too resource intensive to open and close a connection for
each method that loads data?