TransactionScope, where is begin transaction on sql profiler?

一曲冷凌霜 提交于 2019-12-30 05:57:14

问题


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?


回答1:


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:.



来源:https://stackoverflow.com/questions/6635445/transactionscope-where-is-begin-transaction-on-sql-profiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!