Re: Will a connection opened in a using block automatically close before being disposed by W
W
Thu Sep 30 21:57:09 CDT 2004
As a matter of style, I call .Close() explicitly AND use the using
construct - however the main reason that I do this is just to explicitly
state what I'm doing as opposed to necessity. When .Dispose is called, the
connection string information is removed from the connection object and then
it calls .Close() - for all intents and purposes they are virtually
identical. As an aside, if you don't get in the habit of calling close()
explicitly you need to be darned sure you ALWAYS use using or you can easily
get yourself in some trouble.
I'd suggest that this isn't the culprit, at least not directly. Run a Trace
during a period that you usually see the resources dry up and make sure that
you aren't firing extra queries in a loop somewhere and that some other
component or application isn't the one eating up the connections.
HTH,
Bill
"Jason" <nfr@nospam.com> wrote in message
news:ed5J$xypEHA.596@TK2MSFTNGP11.phx.gbl...
> We are having problems where connections in a connection pool are being
> exausted. We are using the Microsoft Application Block SQL Helper class
and
> are seeing the failure in the following method:
>
> public static int ExecuteNonQuery(string connectionString, CommandType
> commandType, string commandText, params SqlParameter[] commandParameters)
> {
> if( connectionString == null || connectionString.Length == 0 ) throw
new
> ArgumentNullException( "connectionString" );
> using (SqlConnection connection = new SqlConnection(connectionString))
> {
> connection.Open();
> return ExecuteNonQuery(connection, commandType, commandText,
> commandParameters);
> }
> }
>
> The application is Client/Server and it is difficult to understand why we
> are running out of resources in the connection pool unless there is
> something about the using block rather than explicity calling close that
may
> be causing the problem.
>
>