简体   繁体   中英

Get SQL from transaction before commit

I am developing a project in C# with a SQL Server database.

I want to save some information in the database when a query has any conditions, so my idea was have a generic method that launches the commit of the transaction and, if the commit has the conditions required, saves the information.

My question: is there any way to obtain the SQL code of the transaction just before the .commit() ?

For example, something like that:

public void insertInfo(object)
{
     using (Context context = new Context())
     {
         [Do an insert]
         [Do a second insert]
         [Do an update]     

         context.Save()
     }
} 

// In the Context
public void Save()
{
    [Here I want to get the SQL statement(s) that will be affected by the "transaction.Commit()"]
   transaction.Commit();
}

No there is no built-in command or function that gets the current code of the transaction.

You could build it yourself, by creating a string variable, and every time you execute a command in the function you add it to the variable, and then read the variable when you commit the transaction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM