Alexandre
Alexandre

Reputation: 7212

TransactionScope, where is begin transaction on sql profiler?

i need to do something like this on a transaction context

using(var context = new Ctx())
{

using (TransactionScope tran = new TransactionScope())
{
    decimal debit = 10M;
    int id = 1;

    var data = context.Cashier
        .Where(w => w.ID == id)
        .Select(s => new{ s.Money })
        .Single();


    Cashier cashier = new Cashier(){ ID = id };
    context.Cashier.Attach(cashier);

    cashier.Money = data.Money - debit;
    context.Entry(cashier).Property(p => p.Money ).IsModified = true;

    context.SaveChanges(SaveOptions.None);
    tran.Complete();
}
}

I'm running sql profiler but can't see begin tran, is that block of code correct? Am I missing something?

Upvotes: 16

Views: 6733

Answers (1)

Adam Robinson
Adam Robinson

Reputation: 185643

Like @Marc said in his comment, the messages are probably being filtered out. You would only be picking up T-SQL transaction messages in the default profile, not transaction messages that are sent using the API directly (as TransactionScope does).

In SQL Server Profiler, go to the trace event selection and check the "Show All Events" checkbox. Down at the bottom is a "Transactions" category, and it should give you what you need. Specifically, the events starting with TM:.

Upvotes: 25

Related Questions