c# - DbContext and Connection pools -


in application i've inherited there's in base controller, every other controller in application inherits from.

public basecontroller()     {         db = new mydbcontext();          db.database.log = s => debug.write(s);     }   public mydbcontext()         : base("name=mydbcontext")     {         // hack force visual studio deploy entityframework.sqlserver package          var instance = sqlproviderservices.instance;     } 

due way application has been designed, @ least 2 contexts created per request. (it's mvc application , there call homecontroller on every page plus whatever other controllers called particular page.)

my question when dbcontext create connection sql server? when context created, or when query executed?

if it's former, using 2 twice number of connections sql server needed, , if it's latter it's not of issue.

i don't think can refactor in immediate future, not without justification. potential pitfalls of design should aware of?

entity framework 6.1.3

because not attempting create , pass connection in context's constructor, then, yes, others saying, ef get/release connections connection pool needed, not when constructed.

notice quote ef documentation:

connections

by default, context manages connections database. context opens , closes connections needed. example, context opens connection execute query, , closes connection when result sets have been processed.

there cases when want have more control on when connection opens , closes. example, when working sql server compact, opening , closing same connection expensive. can manage process manually using connection property.

see following links more information:

https://msdn.microsoft.com/en-us/data/jj729737

https://msdn.microsoft.com/en-us/data/dn456849


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -