I am suddenly getting this error, on production, in my log file:
System.Web.HttpException (0x80004005): Exception of type 'System.Web.HttpException' was thrown.
System.Web.HttpException (0x80004005): Unable to connect to SQL Server session database.
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.
I looked at a lot of other answers like here
but I don't have connections leak and I don't want only to set the max pool to 200 or so because I want to understand why I suddenly get this exception...
These are my connection strings:
<!--Nhibernate-->
<add name="name"
connectionString="Server= servername;Initial Catalog=DBname;UID=username;Password=password;MultipleActiveResultSets=true"
providerName="System.Data.SqlClient" />
<!--Entity Framework-->
<add name="name"
connectionString= "metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=servername;initial catalog=DBname;user id=userName;password=password;multipleactiveresultsets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
Update
An example of using db without connections leaks:
using (var db = new dbName())
{
using (var connection = db.Database.Connection)
{
var command = connection.CreateCommand();
...
connection.Open();
using (var reader = command.ExecuteReader())
{
...
reader.NextResult();
...
reader.NextResult();
...
reader.NextResult();
...
}
connection.Close();
}
}
UPDATE
It turns out that I indeed had a connections leak in Entity Framework,
a place that didn't use using, and the connections didn't closed!
Example:
private DbContext context = new DbContext();
...
List<dbObject> SeriesEvents = context.dbObject.Where(e => e.RecurrenceId == entity.RecurrenceId).ToList();
the context variable is not getting closed.
I more thing is that this query made a lot of DB queries more than a 100.