472,354 Members | 1,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

manually closing DB connections...required?

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
Nov 18 '05 #1
7 1334
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" <no*****@hotmail.com> wrote in message
news:u0**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #2
> 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
Nov 18 '05 #3
> 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
Nov 18 '05 #4
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
Nov 18 '05 #5
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" <no*****@hotmail.com> wrote in message
news:#R**************@tk2msftngp13.phx.gbl...
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

Nov 18 '05 #6
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" <no*****@hotmail.com> wrote in message
news:Od*************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #7
> Hi Darrel,

No, that' s not necessary.


Thanks, Kevin!

-Darrel
Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
4
by: dustin lee | last post by:
Over the years I've gotten out of the habit of explicitly closing file objects (whether for reading or writing) since the right thing always seems to happen auto-magically (e.g. files get written...
3
by: Anthony | last post by:
Hey all, Here's a question for you, my hosts have told me that that one my pages, php, was causing their server to reboot because there were too many open connections and that they should be...
6
by: MAB71 | last post by:
There should be a way to copy an access database ( .mdb file ) without closing connections to it. Unfortunately the FileCopy statement in VB gives an error if users are connected to the db. But I...
1
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and...
3
by: blakecaraway | last post by:
Hi there. I have a C# console application that extracts data to flat files. Some of my business partners begin consuming these extract files before I've had a chance to write the newest ones (I...
13
by: Simon Harvey | last post by:
Hi All, I have a colleague that I wprk with that develops using ASP. I develop using ASP.net. He seems to make sites much faster than me and I am wondering if its because of the two different...
7
by: Tumurbaatar S. | last post by:
Is it so important to close database connections? As I understand, after processing a request and sending a response, page object destroyed. So all used connections also destroyed. Yes?
7
by: Martien van Wanrooij | last post by:
I have been faced a couple of times with the situation that I wanted to write a script and was worried about a too frequent opening and closing mysql connections. To give some examples: 1)I...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.