My team and I have been developing this MVC application for about 3 years now, and all of the sudden we starting getting errors when communicating with the DB, and after some desperate search, and several users' discomfort, we were able to actually get it up and running by adding Pooling=False
to the connection string for our EF DbContext
.
I have been making some research and came across these links:
Tuning up ADO.net connection pooling on Asp.Net applications
A few on Autofac and
IDisposable
behavior:
For my DbContext
objects I have the Lifetime Scope set as InstancePerRequest()
which, if I'm not wrong, means that once the request is served/finished then Autofac will call the Dispose()
method on the DbContext
and it should release the SqlConnection
and ideally return it to the pool.
So my question is:
Should I do anything special to manually call DbContext.Dispose()
?
Is there anything I'm missing how EF handles DB connections?
Edit
This is part of my logs:
"TypeName":"System.InvalidOperationException",
"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.", "Source":"System.Data",
"Detail":"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.
that's the error I was getting when attempting to connect to the DB