Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 289
Alexandre Avatar asked Jul 09 '11 14:07

Alexandre


People also ask

What SQL command begins a transaction?

BEGIN TRANSACTION (Transact-SQL)

What is start transaction commit transaction?

Transaction Control The following are the commands used to control transactions: BEGIN TRANSACTION: It is a command that indicates the beginning of each transaction. COMMIT: It is a command used to save the changes permanently in the database.

How do I see triggers in SQL Profiler?

In SQL Server Profiler 2008, when starting/configuring the trace, go to the "Events Selection" tab, click on the "Show all events" checkbox, and then in the list under the Stored Procedures section select the SP:StmtStarting and SP:StmtCompleted events to be included in the trace.

What is transaction scope in SQL Server?

Definition: TransactionalScope makes your code block Transactional. You can easily maintain one transaction for multiple databases or a single database with multiple connectionstrings, using TransactionScope. When you use TransactionScope there is no need to close any Database connections in the middle.


1 Answers

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

like image 96
Adam Robinson Avatar answered Sep 25 '22 23:09

Adam Robinson