Max pool size for database connection pool problems

Source: Internet
Author: User
Tags finally block stack trace

The timeout has reached. 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.

Note: An unhandled exception occurs during the execution of the current Web request. Check the stack trace information to learn about this error andCodeDetailed information about the cause of the error.

Exception details: system. invalidoperationexception: the timeout has reached. 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.

This is an old problem! You can check two points:

1. check whether all open connections are closed.

2. If the traffic volume is large and the Max pool size = 512 clause is added, of course, this is at the cost of system loss! This will definitely solve your problem in the future!

Solution 1

I think it may be because of concurrent operations. Datareader is exclusively connected, that is, yourProgramThere may be design problems. For example, if the maximum connection is set to 100 and 100 users use datareader to read the database content at the same time, the above error occurs when the connection pool is no longer connected when 101st users read the data. Datareader is exclusively connected, and each datareader occupies a connection. Of course, this happens occasionally, so it takes a long time, because only concurrent operations that exceed the maximum number of connections in the connection pool will occur. In addition, you can only temporarily reduce the number of concurrent connections. If you increase the number of concurrent connections to 200, what if there are 201 concurrent operations? You said that you can't use the close () method of the connection object, because the close () method only closes the connection, but this connection is not released and is still occupied by this object, to release a connection, you must use the dispose () method of the connection to explicitly release the connection. Otherwise, the connection occupied by this object can be released only when garbage collection occurs. In this case, the error "time-out has reached" will certainly occur.

Solution:

1. modify several key pages or frequently accessed database access operations. Use dataadapter and dataset to obtain database data. Do not use datareader.

2. Use the data cache on the page for accessing the database. If the data on the page is not updated frequently (updated several minutes), the cache object can be used without accessing the database, this greatly reduces the number of connections.

3. modify the code and call dispose () after close.

4. We recommend that you modify Database Operations to create your own database operation proxy class, inherit from the system. idisposable interface, and forcibly release resources. In this way, there will be no insufficient connections.

Solution 2

Solution (*): Web. in config: Add Max pool size = 512; server = Local; uid =; Pwd =; database = 2004; Max pool size = 512; "> once and for all.

Solution 3

It is estimated that the connection object is not close. You don't need to dispose, but datareader should be closed after it is used up, but it is okay if it is not closed, but the connection object will never be used, as long as you close the connection object, there will be no problems. The operations of the connected object after open are put in the try block, followed by a Finally block: conn. Close ();

Reprinted: http://blog.csdn.net/villison/archive/2009/11/12/4797925.aspx

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.