943,800 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1311
  • ASP.NET RSS
Dec 3rd, 2008
0

When to close a db connection?

Expand Post »
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

ASP.NET Syntax (Toggle Plain Text)
  1. DbComm.Parameters.Clear()
  2. DbComm.Dispose()
  3. DbRead.Close()

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

Thanks,

David.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mcgarry101 is offline Offline
19 posts
since Apr 2008
Dec 4th, 2008
0

Re: When to close a db connection?

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
Reputation Points: 26
Solved Threads: 19
Posting Whiz in Training
Traicey is offline Offline
283 posts
since Mar 2008
Dec 4th, 2008
0

Re: When to close a db connection?

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.
Reputation Points: 17
Solved Threads: 3
Junior Poster
PirateTUX is offline Offline
101 posts
since Jan 2007
Dec 16th, 2008
0

Re: When to close a db connection?

Placing all the DB code inside the Using keyword takes care of all the resource issues automatically.
Reputation Points: 25
Solved Threads: 18
Practically a Master Poster
binoj_daniel is offline Offline
645 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: which one is better asp.net or jsp?
Next Thread in ASP.NET Forum Timeline: Problem with reading the html email templates





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC