- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在阅读有关 TransactionScope 的内容,并对它与 ADO.Net 事务的互操作性有疑问。现在我们有一些数据访问方法,每个方法都调用存储过程并开始和提交自己的单独事务。简单明了,样板的东西,方法如下所示:
sqlCommand = //create SQLCommand with Stored proc
SqlTransaction myTransaction = myConnection.BeginTransaction();
sqlCommand.Transaction = sqlTransaction;
sqlCommand.Execute();
sqlTransaction.Commit();
我已经简化了一些事情,但你明白了。
我现在需要连续调用其中两个类方法,并从我的业务层作为一个团队提交或回滚它们。我无法修改数据方法,因此我正在考虑将这两个调用放在 TransactionScope block 中。
如果我这样做,在创建 TransactionScope 时应该使用什么类型的参数?我已经使用 TransactionScopeOption.RequiresNew 选项尝试过此操作,并且似乎有效,但这只是我的实验,我不确定这是否是可行的方法。 (我会在这里指出,这些是专门的 SQL 事务,在同一 SQL 服务器上运行。)
我看到 TransactionScope 有构造函数选项来处理 COM+ 事务。因为我使用的是 ADO.Net 事务,所以这与这里相关吗?感谢您的建议。
最佳答案
TransactionScope 文档 here是一个很好的起点。
基本上,它使得在 ADO 级别处理事务变得不必要。连接将自动考虑现有的环境事务(默认)。
请记住,您还可以通过连接字符串更改连接在环境事务中登记的方式。这个link将提供更多详细信息。
Enlist 'true'. true indicates that the SQL Server connection pooler automatically enlists the connection in the creation thread's current transaction context.
关于ado.net - 在 TransactionScope 中使用 ADO.Net 事务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1786591/
我有一个应用程序,我想将多个数据库保存到一个事务中。如果他们中的任何一个失败了,我想把整个事情都推回去。但是,我想在回滚事务之前知道其中哪些失败(或成功)。 我有一个带有内部循环的外部 Transac
我刚刚开始玩 Dapper。到目前为止我很喜欢它。 dapper 不能与 TransactionScope 一起使用吗?我注意到,即使我从不调用 TransactionScope.Complete,我
您好首先感谢您对这个问题的关注;有没有办法在c#中实现这样的事务 using (Transactionscope x=new Transactionscope ()) { Thead A()=>
这是使用事务范围的正确方法吗: 我有一个代表事物的一部分的对象: public class ThingPart { private DbProviderFactory connectionFa
我正在尝试找到在使用 NHibernate 的 Web 应用程序中处理事务的最佳解决方案。 我们使用 IHttpModule 并在 HttpApplication.BeginRequest 我们打开一
我面临以下问题: 在我的项目中,我在应用程序正在使用的同一个数据库中进行了错误登录。这意味着,如果发生错误,那么在每个 catch 中,都会将错误存储到 DB 中。 然而,问题是在使用事务时。发生错误
我想知道在处理多线程时如何正确使用 TransactionScope 类? 我们在主线程中创建一个新的作用域,然后生成几个工作线程,我们希望它们参与主作用域,因此,如果作用域从未完成,则在每个工作线程
任何人都可以给我一个关于使用 TransactionScope 和 NHibernate 的快速概述吗?我需要对 session /IEnlistmentNotification/等做一些特别的事情吗
如果我执行以下操作: Using scope = New TransactionScope() entries.Content.ReadAs(Of IList(Of WebMaint
当 TransactionScope 首次推出时,我在让它在我的开发机器 (XP) 和我们的数据库服务器 (Windows Server 2003) 之间工作时遇到了一些严重的问题。 当我进一步研究时
我在基于 Silverlight 和 RIA 服务的项目中使用 TransactionScope 类。每次我需要保存一些数据时,我都会创建一个 TransactionScope 对象,使用 Oracl
TransactionScope 是否适用于封闭的数据库连接? using (var transaction = new TransactionScope(TransactionScopeOption
我有两个 PL/SQL 存储过程,每个过程都处理自己的事务(开始/提交和发生错误时的回滚)。从 .Net 代码我调用这两个 SP,如下所示。 using (TransactionScope ts
我在我的应用程序中使用了 TransactionScope 类,因为我需要以交互方式、自然地执行一些操作(要么全部成功,要么全都不成功)。 由于此操作不仅与数据库相关,我通过实现 IEnlistmen
您好,有没有办法检查使用 TransactionScope 的事务是提交还是回滚? 最佳答案 在处理 TransactionScope 之前,实际的提交不会发生。如果 Commit 由于任何原因失败,
我有一个 Web 应用程序,许多用户在任何给定时刻都在使用它。从数据库的角度来看,他们在系统中移动时不断地从任意数量的表中写入和读取数据。此外,我们还有许多将数据导入该系统的流程。 今天,在调试导入过
我正在开发一个使用 C# 和 SQL Server 作为数据库的 .NET Web 应用程序,我是这两种技术的新手。当我尝试同时保存大量信息时遇到问题。 我的代码很简单: SqlConnectio
您好,我在我的应用程序的多个位置使用了 TransactionScope。喜欢: using (var scope = new TransactionScope()) { ToDo1(
我在服务器端代码 (WCF) 中使用 TransactionScope 类时遇到性能问题。 我的代码从客户端获取请求,创建 TransactionScope 并执行短操作(通常最多 100 毫秒)。
我正在处理一个几乎不存在事务的遗留项目,这会在出现错误时导致大量的部分提交。 SQL 调用混合了原始 ADO、Linq to Entities 和 EntityFramework,我想让它们在事务中运
我是一名优秀的程序员,十分优秀!