Big trouble with connections

  • Thread starter Thread starter Alberto
  • Start date Start date
A

Alberto

In my application I close all the connections but a few ones that I can´t so
I close them in this way:

miCommand.ExecuteReader (CommandBehavior.CloseConnection);

From time to time I see an error message saying more or less that "the wait
time has expired before get a connection to the group. This may occur
because all the connections of the group was in use and maximum size of the
group was reached".

How can I solve this?

Thank you very much
 
Hi Alberto
Try from you connection string, in the connection pooling options to
increase the pool size. Hope this helps

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Alberto said:
In my application I close all the connections but a few ones that I can´t so
I close them in this way:

miCommand.ExecuteReader (CommandBehavior.CloseConnection);

This alone does not close the connection. The connection is closed (or
returned to the connection pool if you have pooling on) only after you call
Close or Dispose on the SqlDataReader.

As a side-note, whenever I suspect there is a connection leak somewhere I
first check that SqlDataReaders are closed properly, and more often than not
it turns out that a programmer forgets to Close the datareader. And even in
the case that the code calls Close, many times the code is not exception
safe which is almost as bad as not calling Close in the first place.

This is also the reason why SqlDataReaders should never be returned from a
data access layer component, as IMO it is way too easy to get it wrong.

Sorry for the rant,
Sami
 
Back
Top