Ilya Chumakov
Ilya Chumakov

Reputation: 25019

Entity Framework: how to find transaction isolation level in SQL Profiler?

BeginTransaction method is used to manage transactions in Entity Framework 6. It allows to set isolation level for transaction as you may see in code below (just a sample):

using (var context = new DataContext())
{
    using (var transaction = context.Database.BeginTransaction(IsolationLevel.Serializable))
    {
        context.Entities.Add(new Entity());

        context.SaveChanges();

        transaction.Commit();
    } 
}

The problem is: when I use SQL Server Profiler, I cann't find any information about isolation level for real SQL transaction.

Attempt #1:

I tried to trace ALL kinds of events and search by "isolation" keyword in trace results. Only two events I found:

EventClass          TextData
-------------------------------------------------------------
ExistingConnection  set transaction isolation level read committed
AuditLogin          set transaction isolation level read committed

READ COMMITTED is always in these events. So it is not about my code, because IsolationLevel.Serializable is set above.

Attempt #2:

For the transaction has been started and not committed yet, it is possible to take SPID and manually select real isolation level from dm_exec_sessions view:

SELECT transaction_isolation_level
FROM sys.dm_exec_sessions
WHERE session_id = @Tran_SPID

This is very undesirable way.

Is it possible to record isolation level for any EF-generated transaction/session in profiler directly? Maybe I just use wrong tool?

P.S. Entity Framework 6.1.3 and MS SQL Server 2012 on board.

Upvotes: 11

Views: 4295

Answers (2)

XAMT
XAMT

Reputation: 1627

You picked the wrong tools because with Entity Framework Profiler you can easily check the isolation level (and lots of information about EF behaviour).

This is my transaction sample :

begin transaction with isolation level: ReadCommitted

EF Profiler

More info : https://hibernatingrhinos.com/products/efprof/learn

Upvotes: 1

Alex
Alex

Reputation: 5157

You cannot find a transaction isolation level in profiler as it is never recorded. See How to monitor transaction isolation level changes in SQL Profiler or in any other tool for explanation.

Upvotes: 1

Related Questions