0

in an action I've instantiated my DbContext through a using block:

using(var context = new DbContext())
{
    //EF codes
}

inside the block, I'm making several queries to the database. I thought that using block opens one connection and all queries use the same one connection.

but then I added Glimpse and I see that there are 7 connections not one! and no Transactions.

enter image description here

what is wrong? did I misunderstand the DbContext behavior? or what ?

Update:

I just checked it with ExpressProfiler and this is the result. after each command there is a sp_reset_connection.

Note : PSID is the same (52) for all commands.

enter image description here

thanks in advance.

mohsen dorparasti
  • 8,107
  • 7
  • 41
  • 61
  • what does sql profiler or https://expressprofiler.codeplex.com/ says ? – tschmit007 Mar 26 '15 at 12:13
  • @tschmit007 : updated the question with ExpressProfiler – mohsen dorparasti Mar 26 '15 at 13:02
  • the SPID column would be great – tschmit007 Mar 26 '15 at 13:22
  • @tschmit007 PSID is the same for all commands. – mohsen dorparasti Mar 26 '15 at 13:28
  • so there is only one connection and the information of Glimpse should be intepreted. By the way: http://stackoverflow.com/questions/641120/what-exec-sp-reset-connection-shown-in-sql-profiler-means – tschmit007 Mar 26 '15 at 13:39
  • Glimpse works by watching the underlying use of the Connections/Commands/etc at an ADO level. Hence, if its saying that there are 7 connections at play here, I would say with a largish degree of confidence that at least at an ADO level, 7 connections are being created. Why this is the case I'm not sure. I would be interested if this is the same in your test environment. The question in my mind is "Why is EF using multiple connections in the one context". – anthonyv Mar 26 '15 at 18:05

0 Answers0