open connection

  • Thread starter Thread starter Venue
  • Start date Start date
V

Venue

Is it a good idea to keep the database connection always open (and keep
using it) and close it only when one exits the application. Any overhead?
 
Hmmm... well, if you are talking about anything other than the PDA, then the
answer is categorically NO! If you are connecting to a database through the
network the same holds. there's all downside to leaving connections open in
almost every instance. On the PDA, there can be even more problems unless
you are totally positive nothing else will need your SQLCE database. Even
then, I think there's a lot more downside than upside....

HTH,

Bill
 
I meant on handheld and using CF. What can be the downside, if at any given
time a single application will be using the database and most of the clicks
on the form would read or write database. Wouldn't in this scenario an
always open connection a better idea.
 
Think about the likely scenarios. For example, your application may raise an
unhandle exception, which case the database connection is NEVER closed and
will be open until you reset the device. It's never a good thing to have
stale connections lying around, especially with SQL Server CE.

--Neil
 
Realising the potential error of my ways, I changed some code to open
and close as suggested. There is a performance hit (depending on
expectation, it could be a big or non important one), but I guess in the
end it is a trade off between how bomb-proof you want your app, and how
fast it needs to run...

Paul
 
If the app bombs, are the file handles cleaned up automatically? At least
that's the way it is on the desktop
 
Back
Top