Hi,

just a quick question from a newbie! I have recently inherited an asp.net website from an ex-colleague and I have a question regarding db connections. I am using vb.net for code behind with an oracle 9 database. The site at the moment, sets up a database connection GDBConn in the session_start sub found in global.asax.vb. This is then used throughout the site. It then doesnt close it until the session_end. However, I was wondering if anyone could tell me if it would be better to be closing these connections immediately after using them. For example, I have a fillGridView function I use to fill my gridviews. In the finally section of this should I be closing my db connection? I am already calling

DbComm.Parameters.Clear()
DbComm.Dispose()
DbRead.Close()

but should I be closing the connection too?
Any help would be really appreciated.

Thanks,

David.

Yah sure if u open the connection u surely need to close it and the best way to close connection is to close it in a finally statement if u have try/catch statement or just after using it, it is not a good practise to leave the connection open and it also bogs down the DB Server, so close it whenever u opened it

I concur... I always close my DB connections right after I'm done with whatever group of transactions I needed the connection for. It makes it easier for me to remember when things are cleaned up, and doesn't leave any connections dangling opened.

This article has been dead for over six months. Start a new discussion instead.