隐式和显式事务的区别 [英] Difference between Implicit and Explicit Transaction

查看:42
本文介绍了隐式和显式事务的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sql Server 2008 中隐式和显式事务有什么区别?

What is the difference between Implicit and Explicit transaction in Sql Server 2008?

在 TransactionScope 背景中会发生什么?我正在使用 TransactionScope,但在 Sql server profiler 中我没有看到Begin transaction..."语句.

What happens in TransactionScope background? I'm using TransactionScope but in Sql server profiler I don't see "Begin transaction..." statement.

它是如何工作的?

推荐答案

  • 隐式事务:http://msdn.microsoft.com/en-us/library/ms188317.aspx
  • 设置 IMPLICIT_TRANSACTIONS { ON |关闭} http://msdn.microsoft.com/en-us/library/ms187807.aspx
  • 基本上,在 c# 中,当您将 TransactionScope 设置为 Implicit 时,它会调用 SQL Server SET 命令将连接置于 IMPLICIT_TRANSACTIONS 模式.您所做的任何事情(使用第二个链接中列出的命令之一)都会启动一个事务,该事务保持打开状态,直到 一个提交被发出.如果在连接结束时没有提交提交,则执行隐式 ROLLBACK.

    Basically, in c# when you set the TransactionScope to Implicit, it calls the SQL Server SET command to put the connection in IMPLICIT_TRANSACTIONS mode. Anything that you do (using one of the commands listed in the 2nd link) starts a transaction that is kept open until a commit is issued. If no commit is issued at the end of a connection, an implicit ROLLBACK is performed.

    这与 OFF 设​​置不同,OFF 设​​置也将每个语句放入一个事务中 - 不同之处在于在 OFF 模式下(因此事务是显式的),每个事务(单个语句)立即提交.

    This differs from the OFF setting, which also puts every statement into a transaction - the difference is that in the OFF mode (therefore transactions are explicit), each transaction (singular statement) is immediately committed.

    这篇关于隐式和显式事务的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆