Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > manually closing DB connections...required?

Reply
Thread Tools

manually closing DB connections...required?

 
 
darrel
Guest
Posts: n/a
 
      10-14-2004
We're running into a problem on our new site. Once a week or so, our site
goes down with an 'out of memory error'. Rebooting the web server fixes
things. Googling the error doesn't return many results (one, actually) and
the suggested fix is to make sure you are manually closing all DB
connections. I'm doing that now, but I had thought that asp.net had fairly
robust automated cleanup, and that having to explicitely close every
connection wasn't necessarily needed (though I certainly agree that it's
good practice). Just curious as to what .net's clean-up capabilities
actually are.

-Darrel


 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      10-14-2004
Hi darrel,

It's not a matter of .Net's cleanup capabilities. It's a matter of the
nature of database connections in .Net. What I mean is that it has nothing
to do with global .Net operations, such as garbage collection. It is
specific to database connections, due to their nature. You will find the
same type of thing with .Net classes that open and close files, and use
unmanaged resources "under the hood". For example, if you open a file, you
had better close it, or it will become unusable (until the next reboot).
Why? Because that's how the file system works. It locks files when they are
opened, and unlocks them when they are closed. A database connection is
similar, in that, you can open it and it will remain open (and in memory)
until you close it. While the connection at your end may be unused when
you're finished using it, it is still connected to the database at the other
end. Closing it disconnects it, allowing it to be cleaned up.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"darrel" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> We're running into a problem on our new site. Once a week or so, our site
> goes down with an 'out of memory error'. Rebooting the web server fixes
> things. Googling the error doesn't return many results (one, actually) and
> the suggested fix is to make sure you are manually closing all DB
> connections. I'm doing that now, but I had thought that asp.net had fairly
> robust automated cleanup, and that having to explicitely close every
> connection wasn't necessarily needed (though I certainly agree that it's
> good practice). Just curious as to what .net's clean-up capabilities
> actually are.
>
> -Darrel
>
>



 
Reply With Quote
 
 
 
 
darrel
Guest
Posts: n/a
 
      10-14-2004
> While the connection at your end may be unused when
> you're finished using it, it is still connected to the database at the

other
> end. Closing it disconnects it, allowing it to be cleaned up.


Yikes! Wow...we screwed this one up, then. ;o)

Ok, I'm halfway through closing all our connections. This is definitely the
problem (and our fault). Thanks for clarifying that for me!

-Darrel


 
Reply With Quote
 
darrel
Guest
Posts: n/a
 
      10-14-2004
> While the connection at your end may be unused when
> you're finished using it, it is still connected to the database at the

other
> end. Closing it disconnects it, allowing it to be cleaned up.


While we're on this topic...is there a log anywhere or any way to see the
current open DB connections?

-Darrel


 
Reply With Quote
 
darrel
Guest
Posts: n/a
 
      10-14-2004
Oh...one more question...what is the '= nothing' for, and is that something
I should have as well?

For instance, I had:

objConnect.open()

I am now adding:
objConnect.close()

but should I also add:

objConnect = nothing

-Darrel


 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      10-14-2004
Hi Darrel,

The following .Net SDK article should be helpful. Along with describing
Connection Pooling, it provides several performanc counters that you can use
to view Connections:

http://msdn.microsoft.com/library/de...taProvider.asp

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"darrel" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> > While the connection at your end may be unused when
> > you're finished using it, it is still connected to the database at the

> other
> > end. Closing it disconnects it, allowing it to be cleaned up.

>
> While we're on this topic...is there a log anywhere or any way to see the
> current open DB connections?
>
> -Darrel
>
>



 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      10-15-2004
Hi Darrel,

No, that' s not necessary.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"darrel" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Oh...one more question...what is the '= nothing' for, and is that

something
> I should have as well?
>
> For instance, I had:
>
> objConnect.open()
>
> I am now adding:
> objConnect.close()
>
> but should I also add:
>
> objConnect = nothing
>
> -Darrel
>
>



 
Reply With Quote
 
darrel
Guest
Posts: n/a
 
      10-15-2004
> Hi Darrel,
>
> No, that' s not necessary.


Thanks, Kevin!

-Darrel


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing the DropDownExtender's Panel manually Abbas ASP .Net 0 07-26-2007 08:00 AM
Closing popup window when closing parent window? =?Utf-8?B?Vk1J?= ASP .Net 3 02-15-2007 08:29 AM
How to manually disconnect from wireless in Windows? =?Utf-8?B?RGFu?= Wireless Networking 1 08-29-2005 11:20 PM
Closing the doors 15 minutes before closing. doofus Computer Support 12 06-11-2005 08:20 AM
Closing child window WITHOUT closing parent thomas Javascript 0 10-23-2003 04:10 PM



Advertisments