Re: Max pool size reached exception when trying to open a new connection




Make absolutely sure you call :

datareader.Close()

this is more important than anything else. datareader = null ......is not
the key phrase to use. it doesn't hurt, but doesn't help like dr.Close
does.


Private Function GoodDataReaderCode(ByVal dataReader As IDataReader)
As Something


''NOTES // http://www.stevearnott.com/DAAG.pdf
'When accessing data by using the reader, use the typed accessor
methods (such
'as GetInt32 and GetString) if you know the column's underlying
data type
'because they reduce the amount of type conversion required when
you read
'column data.


Try

While dataReader.Read()




If Not dataReader.IsDBNull(0)


End If
End While


Finally


'NOTES // http://www.stevearnott.com/DAAG.pdf
'The underlying connection to the database remains open and
'cannot be used for
'any other purpose while the data reader is active.
'Call Close on the
'SqlDataReader as soon as possible.


If Not (dataReader Is Nothing) Then
Try
dataReader.Close()
Catch
End Try
End If
End Try

End Function







private Something GoodDataReaderCode(IDataReader dataReader)
{
try {
while (dataReader.Read()) {
if (!(dataReader.IsDBNull(0))) {
}
}
} finally {



/*
'NOTES // http://www.stevearnott.com/DAAG.pdf
'The underlying connection to the database remains open and
'cannot be used for
'any other purpose while the data reader is active.
'Call Close on the
'SqlDataReader as soon as possible.
*/


if (!((dataReader == null))) {
try {
dataReader.Close();
} catch {
}
}
}
}


<ramneekm@xxxxxxxxx> wrote in message
news:1171294813.953642.186650@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hi all,

i am working on a asp.net web app and using ado.net 's SqlClient Data
Provider to connect to
sqlserver 2005. I am getting the exception "Timeout expired. 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." . Internally i
am using a
sqldatareader to fetch data from database. The dispose of both the
reader and connection has
been called wherever they are being used. The pool size is set to
default i.e. 100. I have
tried to analyze the issue by using the sp_who2 stored procedure in
database and checking
the count of connections to the database.What is happpening is that
sometimes the pool size
limit is being maintained and increases 100. But on the other hand, it
sometimes shoot much
above the limit of 100 and then it throws the above mentioned
exception. Why does the
connection pooler sometimes enforces the pool size limit and sometimes
fails to do that
intrigues me.

But if i use GC.Collect in my code, then in that case the connection
pool limit is adhered
to and i dont get the above mentioned exception. Can someone please
help me with it and
explain why is it happening in the first place and is there a way
around it. I don't want to
use GC.Collect() in my code.

Thanks in advance
Ramneek



.



Relevant Pages

  • Re: DataView vs DataReader
    ... This is because the reader maintains an open ... connection to the database - a valuable resource. ... Now, a dataview, has nothing to do with database access itself. ... I definitely recommend you go ahead and eliminate the datareader. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Where is the database connection pool locating?
    ... authentication. ... Pool Fragmentation Due to Integrated Security ... Connections are pooled according to the connection string plus the user ... Although this improves the performance of subsequent database ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How to clear connection pool?
    ... SQLConnection (SQL Server database), the pool size can be configured. ... >> connection problems when 100+ people have been connecting to the ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Oracle Connectivity/Windows Service
    ... OracleConnection probably maintains a connection pool, ... When you restart the database server, ... Does restarting your Windows Service machine help? ...
    (microsoft.public.dotnet.framework.adonet)
  • DataView vs DataReader
    ... Hi all, quick question, a DataView is ... effect the number of connections to the database. ... A DataReader on the other hand always maintains a connection to the database ...
    (microsoft.public.dotnet.framework.aspnet)