2

In highload legacy application I've found tons of code which just creates new DBContext, then makes request and doesn't dispose the DBContext at all.

Monitoring shows 200 connections opened all the time and disposing all DBContext doesn't resolve this issue.

Connection pooling is by default. Database: MariaDB. If it's important, this is servicestack

Could you please share ideas on how to resolve this: decrease the level of opened connection so that the number of opened connection would correlate with the REAL number of connection from DBContext.

Also I've looked through the following links:

DbContext disposing?

EF DBContext dispose not closing the connection

Not Using Dispose or Using() in Entity Framework

Should i use Pooling=False in Entity Framework Connection String?

Entity Framework and Connection Pooling

Dmitry Dyachkov
  • 1,371
  • 2
  • 14
  • 38
  • As far as I know, when DbContext is disposed, its connection is keeping alive by ADO.Net connection pool. It is "by-design" and I'm not sure why do need to actually close them, but I beleave this can be done by disabling connection pooling. So, do you try something from links you provide? – vasily.sib Sep 21 '18 at 03:15
  • 1
    https://blog.jongallant.com/2012/10/do-i-have-to-call-dispose-on-dbcontext/ – Moho Sep 21 '18 at 19:04

0 Answers0