The timeout time has reached, but the connection has not been obtained from the pool. This may occur because all pool connections are in use and the maximum pool size is reached.

Source: Internet
Author: User
ASP. net c # This prompt appears when you use sqldatareader to read data. I found some answers online and did not solve the problem. Finally, I found the answer to Microsoft's petshop.
I used sqldatareader in a loop:
Using (sqldatareader reader = sqlhelper. executereader ("select * From region where fatherid = 0 "))
{
While (reader. Read ())
{
// Store the province-level zoning in a dictionary for backup
Province. Add (Reader ["name"]. tostring (), Int. parse (Reader ["ID"]. tostring ()));
}
}
Although it is the sqldatareader declared in the using statement Program After running the command several times, the error indicated by the title still appears. When checking process information in manage studio of SQL Server 2005, it is found that only once the program runs, the connection of dozens of databases is not closed (the information of more than 30 provinces should be read at a time ). After running the program two or three times, the program crashes. When the process information reaches more than 120, the program crashes.
So it is strange that the closed connection is also closed. Connection and sqldatareader are both declared in the using statement. How can the connection not be closed?
After comparing the sqlhelper class I wrote with the executereader method in the sqlhelper class in petshop, we found that cmd. executereader () in his executereader method calls a parameter: commandbehavior. closeconnection.
Cmd. executereader (commandbehavior. closeconnection)
The description of this parameter in msdn is: if the associated   Datareader   Object, the associated Connection   The object will also be disabled.
That is to say, if the sqldatareader is strictly declared in the using statement, the sqldatareader is closed only after the program ends, and the connection associated with the sqldatareader is not closed (or released). Therefore, when an associated object is opened, you must also explicitly disable the associated object, that is, commandbehavior. the function provided by the closeconnection parameter.
After this parameter is used, there is no problem when the program is run multiple times, and the number of connections in the process information is always more than 20, of which about 20 are system connections.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.