|
Okay, what's probably going on is you're using connection pooling, and not closing some connections when you're done with them, flooding the pool. Increasing the number of allowed connections won't solve the problem, although it will come up less often. It will also slow your server down in general. Basically, don't go this route.
Even though your database server and web server are probably on the same computer, this isn't always the case, and anyway they're in different software. So the web server builds a connection to the database to be able to talk to it. Trouble is, this is really expensive - it takes a long time ( sometimes several seconds - imagine doing that over and over again to serve a page up ) and it takes up RAM on the database server. So instead of just creating these on the fly and destroying them when they aren't needed, modern applications pool database connections. When you need one, you pull it from the pool ( it's sitting there, idle, so you get it instantly - as long as one is available ) and then when you're done with it, you return it to the pool.
Most connections are open for less than a second, they just do a quick lookup and return some data, like if this is a valid login. So unless they all come in at exactly the same time, you can handle a hundred web requests with four or five database connections.
But if you don't return a connection to the pool, then another request has to build a new one, and you're one closer to your limit. So if a certain bit of code forgets to close a connection, and you hit that functino over and over, you'll slowly creep up toward that limit. On the other hand, the connections will die off after they've been idle a certain amount of time if you don't close them - they'll eventually be marked as "damaged" and cleaned up. So your flooding will go down, but very slowly, and it can go up quickly.
That's why you hit the error sometimes but not others. Or that's how connection pooling works, anyway, and it really sounds like that's your issue.
|