【问题标题】:Get SQL from transaction before commit提交前从事务中获取 SQL
【发布时间】:2018-05-09 18:16:52
【问题描述】:

我正在用 C# 开发一个带有 SQL Server 数据库的项目。

当查询有任何条件时,我想在数据库中保存一些信息,所以我的想法是有一个通用的方法来启动事务的提交,如果提交具有所需的条件,则保存信息。

我的问题:有什么方法可以获取.commit()之前的事务的SQL代码?

例如,类似这样的事情:

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();
}

【问题讨论】:

    标签: c# sql-server database transactions


    【解决方案1】:

    不,没有内置命令或函数可以获取交易的当前代码。

    您可以自己构建它,通过创建一个字符串变量,每次在函数中执行命令时将其添加到变量中,然后在提交事务时读取该变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-25
      • 2018-04-27
      • 2011-12-31
      • 1970-01-01
      • 1970-01-01
      • 2015-07-27
      相关资源
      最近更新 更多