|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Max pool size reached exception when trying to open a new connectioni 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 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 { } } } } <ramne***@gmail.com> wrote in message Show quote news:1171294813.953642.186650@s48g2000cws.googlegroups.com... > 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 > |
|||||||||||||||||||||||