Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The underlying provider failed on Open" when running under IIS

We have a website running on a server. We have a "production" instance and a "staging" instance each having its own database. The MSSQL Server is running locally on the same server.

Today, suddenly the "production" website went down. Looking at the logs, the following exception showed up:

System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.InvalidOperationException: 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.

At the same time, the "staging" website was working just normally.

While trying to figure out what was happening, I tried all sorts of things like re-creating both the app pool and the IIS app. I also hooked up the "production" IIS app to the same app pool of the "staging" app, still the same issue. Restarted the server too of course.

Also, I ran the executable of the "production" website directly (as a console app) and it worked normally. So it's a problem that happens only when running under IIS.

One last thing I tried, is that I reconfigured the "staging" website to use the "production" database, and to my utter shock it worked normally. Because I thought the problem was the "production" database itself.

I just have no idea whatsoever about what's going on here. Any help is very much appreciated.

like image 310
mrahhal Avatar asked Jul 24 '17 17:07

mrahhal


1 Answers

If all the connections in the connection pool are used, it is almost certainly because your application is opening database connections and failing to close them.

Since you are using Entity Framework, it's probably because your application is failing to dispose of the DbContext object.

It's nothing to do with the production database as such; probably the increased activity on your production site vs your staging site is making the application bug manifest itself more quickly.

like image 150
Joe Avatar answered Nov 20 '22 01:11

Joe