Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > Architecture> Adapter's CloseConnection
 

Pages: 1
Architecture
Adapter's CloseConnection
Page:1/1 

  Print all messages in this thread  
Poster Message
obzekt
User



Location:

Joined on:
29-Apr-2004 18:18:59
Posted:
49 posts
# Posted on: 22-Jun-2004 19:53:22.  
Hi. I would like to ask if the adapter closes its internal db connection when an exception occurs and KeepConnectionOpen=true. In other words, is it safe for the the client to code like this:

Code:
DataAccessAdapter adp = new DataAccessAdapter(true);
adp.FetchEntity(..);
adp.FetchEntity(..);
adp.CloseConnection();


or is it expected to do the following to avoid connection leakage:

Code:
DataAccessAdapter adp = new DataAccessAdapter(true);
try {
adp.FetchEntity(..);
adp.FetchEntity(..);
}
finally { adp.CloseConnection(); }


  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37870 posts
# Posted on: 22-Jun-2004 20:29:45.  
The latter is the way to go. The DataAccessAdapter class does close/clean up at dispose, so eventually everything is cleaned up, you don't have control over when that will be (as the GC has to kick in), so cleaning up in a finally is the way to go Regular Smiley

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
obzekt
User



Location:

Joined on:
29-Apr-2004 18:18:59
Posted:
49 posts
# Posted on: 22-Jun-2004 20:40:32.  
I see, that makes sense.

But I assume that in the case of KeepConnectionOpen=false, the adapter closes the connection before throwing the exception back to the caller, so try/finally is *not* required there. Is this correct?

  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37870 posts
# Posted on: 22-Jun-2004 20:48:51.  
obzekt wrote:
I see, that makes sense.

But I assume that in the case of KeepConnectionOpen=false, the adapter closes the connection before throwing the exception back to the caller, so try/finally is *not* required there. Is this correct?

True, if KeepConnectionOpen is false, every call to a method which will access the database will open a connection, use the connection and will close it. An exception internally will close the connection first.

A transaction always keeps a connection open.


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.