【问题标题】:What is the diference in these two ways of transaction handling这两种事务处理方式有什么区别
【发布时间】:2014-08-13 04:54:33
【问题描述】:

这两种事务处理方式有什么区别

第一种方法

//
const string selectSatement = @"INSERT INTO Payment....";
using (SqlTransaction sqlTrans = sqlConnection.BeginTransaction())
using (SqlCommand sqlCommand = new SqlCommand(selectSatement, sqlConnection,sqlTrans))
//
sqlTrans.commit();

第二种方法

BEGIN TRAN T1; 
INSERT INTO Payment....;
COMMIT TRAN T1;

【问题讨论】:

    标签: c# sql .net sql-server transactions


    【解决方案1】:

    使用第一个选项,您可以异步使用数据库连接(多线程)。

    如果您有并行线程在数据库中执行操作,并且您只是在那里转储了BEGIN TRANSACTION,您可能会导致其他线程的查询也被包含在该事务中,并搞砸了如果您必须执行ROLLBACK

    通过使用SqlTransaction,您可以确保只有应该属于事务一部分的查询才会包含在其中。

    【讨论】:

      猜你喜欢
      • 2021-10-01
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 2013-09-08
      • 2019-03-31
      • 2021-09-28
      • 1970-01-01
      相关资源
      最近更新 更多