8

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.

3
  • Weird...Can you check your production config connection string (and prod transform) and make sure no one explicitly set the min/max pool size to something ridiculous. It would be in your actual connection string like so connectionString="Data Source=localhost;Min Pool Size=0;Max Pool Size=100;Pooling=true;..... Commented Jul 24, 2017 at 18:52
  • Also, have you verified that you actually do not in fact have a connection issue happening. You can run "exec sp_who" on your database to see open connections Commented Jul 24, 2017 at 18:59
  • After almost 7 hours, it suddenly started working again. The weird thing is that there was almost no traffic at all when it happened. I've seen almost a thousand users online in the past year regularly and this never happened. I use a similar conn string to the following: data source=.;initial catalog=DatabaseName;persist security info=False;user id=...;password=...;workstation id=localhost;packet size=4096
    – mrahhal
    Commented Jul 24, 2017 at 19:13

1 Answer 1

1

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.

1
  • 1
    Makes sense in a way, but I actually did a restart of the whole server and directly tested it out and the same thing happened. Prod doesn't work, staging works. Also please note again that the traffic was relatively non-existent. And not disposing the DbContext is a bit hard, since there's dependency injection going on.
    – mrahhal
    Commented Jul 24, 2017 at 19:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.