closing db connection --> returning to pool. Should be in finally block?
843835Nov 20 2002 — edited Nov 20 2002hi,
I have read some people say its a bad idea to rely on finally blocks to close/return connections. But isnt it the only true way of assuring that a connection is closed/return.
i.e.,
GetConnection();
//Process a query
CloseConnection();
What if the query gets some type of error and then goes to the catch
i.e.,
catch(Exception e){
//Would need CloseConnection(); here too. Redundant code.
}
Isnt it better to just have a finally block since it is always executed.
catch(Exception e){
//blah blah
}finally{
CloseConnection();
}