473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Connection.Dispose and the connection pool

I am researching some errors with "The timeout period elapsed prior to
obtaining a connection from the pool. This may have occurred because
all pooled connections were in use and max pool size was reached."
message. I am assuming that the connection pool ran out of connections
(though it could certainly be something else).

So I've looked through the code and it does close Connections (in the
finally clause), but doesn't .Dispose of them. Do I have to dispose of
the connections? Do connections not get released unless you dispose of
them?

Thanks
Jul 1 '06 #1
4 5851
Frank,

For most connections, Close and Dispose are the same thing. The reason
I say most is that the base class for connections, DbConnection (or
DbDataConnection, I forget which one it is), the Close method and Dispose
method pretty much share the same code path. However, certain providers can
override that code path.

I would advise not doing it yourself in the finally statement, rather,
just wrapping everything in a using statement.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Rizzo" <no**@none.com> wrote in message
news:ey**************@TK2MSFTNGP04.phx.gbl...
I am researching some errors with "The timeout period elapsed prior to
obtaining a connection from the pool. This may have occurred because all
pooled connections were in use and max pool size was reached." message. I
am assuming that the connection pool ran out of connections (though it
could certainly be something else).

So I've looked through the code and it does close Connections (in the
finally clause), but doesn't .Dispose of them. Do I have to dispose of
the connections? Do connections not get released unless you dispose of
them?

Thanks

Jul 1 '06 #2
Nicholas Paldino [.NET/C# MVP] wrote:
Frank,

For most connections, Close and Dispose are the same thing. The reason
I say most is that the base class for connections, DbConnection (or
DbDataConnection, I forget which one it is), the Close method and Dispose
method pretty much share the same code path. However, certain providers can
override that code path.

I would advise not doing it yourself in the finally statement, rather,
just wrapping everything in a using statement.
However, per your statement, wouldn't this cause a problem, if I were to
use another provider? Since using only calls .Dispose, but not .Close?

Also, why would you advise using the 'using' statement, rather than
manually closing/disposing connections in the finally section? Other
than code clarity, are there any downsides?

Regards

Jul 1 '06 #3
Frank,

I wasn't saying that you should use another provider. I'm saying that
some providers can override the behavior that I mentioned, but for the most
part, they do not.

As for the using statement, you are right, I suggest it for the sake of
code clarity.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Rizzo" <no**@none.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Nicholas Paldino [.NET/C# MVP] wrote:
>Frank,

For most connections, Close and Dispose are the same thing. The
reason I say most is that the base class for connections, DbConnection
(or DbDataConnection, I forget which one it is), the Close method and
Dispose method pretty much share the same code path. However, certain
providers can override that code path.

I would advise not doing it yourself in the finally statement,
rather, just wrapping everything in a using statement.

However, per your statement, wouldn't this cause a problem, if I were to
use another provider? Since using only calls .Dispose, but not .Close?

Also, why would you advise using the 'using' statement, rather than
manually closing/disposing connections in the finally section? Other than
code clarity, are there any downsides?

Regards
>>

Jul 2 '06 #4
Besides clarity, a using statement guarantees that Dispose is called no
matter how you're exiting the block (ie, even if there's an exception).
If you're already calling dispose in a finally block, there will be
no difference except that the code is cleaner.

Andy

Frank Rizzo wrote:
Nicholas Paldino [.NET/C# MVP] wrote:
Frank,

For most connections, Close and Dispose are the same thing. The reason
I say most is that the base class for connections, DbConnection (or
DbDataConnection, I forget which one it is), the Close method and Dispose
method pretty much share the same code path. However, certain providers can
override that code path.

I would advise not doing it yourself in the finally statement, rather,
just wrapping everything in a using statement.
Jul 3 '06 #5

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

Similar topics

5
by: Martin | last post by:
Dear Group Sorry for posting this here. I'm desperate for a solution to this problem and thought some of you might have come across it with .NET and SQL Server. Let's assume I've the following...
3
by: Kamalanathan T. | last post by:
Hi, We have developed an Web application in ASP.NET with C# and we r using SQL Server 2000. We get the Timeout expired error, when more than 300 concurrent users hit the site. I hagone thru...
4
by: Guoqi Zheng | last post by:
Dear sir, I keep getting the following errors on one of my sites after clicking for many times. Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This...
1
by: UJ | last post by:
We have recently started getting the following error message: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled...
0
by: luresh | last post by:
Hi EveryBody : i am using following code ,it is working fine most of the time but some time "Unable to read data from the transport connection: The connection was closed" error occured in the...
7
by: fniles | last post by:
I am using VB.Net 2003 and MS Access (connecting using OleDBConnection). I read using DataAdapter and DataSet, not DataReader. When many people try to access the database at the same time, I get...
6
by: =?Utf-8?B?QnNtZW5nZW4=?= | last post by:
I am trying to make sure that the local connection is up. I have presently been using the NetworkChange.NetworkAvailabilityChanged Event for this. Is there a better way to do this? Also, I...
2
by: Tony Johansson | last post by:
Hello! How does this connection pool function actually ? As I have been told is that when the connection is returned to the pool the connection to the database is still open. What you do is that...
2
by: anumsajeel | last post by:
Hi, Error Message:- error connecting: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.