Search code examples
c#asp.netconnection-pooling

problem regarding maximum pool size in asp.net


I have been working on a small file manager module in a project where a list of folders are shown in a treeview. I have done the whole thing in javascript. Everytime I click a node, a list of data is fetched into a datareader and populated in the front end. But when I deploy the application in IIS, after about 18 subsequent clicks, the IIS is halted and I have to reset it again. When I checked the event viewer I got the following error

Exception type: InvalidOperationException Exception message: 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.

So in my connection string in the web.config, I set pooling to True and max pool size to 200 and the problem was solved.

But I wonder is it a good practice to use connection pool size in this way. Or how do we prevent so many connections from being opened. Thanks!


Solution

  • I think what's happening is that you don't free up unused resources. More specifically, you absolutely must call Dispose() on all database-related objects, like SqlConnection, SqlDataReader, etc. Or, better yet, wrap them in using statements.