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 connection开发者_StackOverflows 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!
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.
A sample connection string for SQL Server:
"Data Source=(local);Initial Catalog=pubs;User ID=sa;Password=;Max Pool Size=75;Min Pool Size=5;"
Do like this may help You:)
Default value of Max Pool size is 100. You can set it to a higher number also so far as performance of the server is not a issue..
精彩评论