Introduction
I got a small project-the schedule management system. When the database is queried during the initialization date, the database is queried once every date, which leads to this problem.
Problem
This may occur because all pool connections are in use and the maximum pool size is reached.
Description: An unhandled exception occurred during the execution of the current Web request. please review the stack trace for more information about the error and where it originated in the code. 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.
Note: An unhandled exception occurs during the execution of the current Web request. Check the stack trace information for details about the error and the source of the error in the code. 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!
Solution
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, your program may be designed incorrectly. 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 the 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 make major changes to database operations, create your own database operation proxy class, and inherit from
The system. idisposable interface forces the release of resources, so that the number of connections is not insufficient.
Solution 2
Solution (*)
In web. config: Add Max pool size = 512 to the database connection; 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 ();