如何在业务逻辑层中实现事务 [英] How To Implement transaction in Business logic layer

查看:309
本文介绍了如何在业务逻辑层中实现事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net应用程序中使用企业库数据访问块。我想实现事务从业务逻辑层,跨多个存储过程。 Entlib打开一个新的数据库访问连接。
以下面的方式使用事务范围导致分布式事务?

 使用(TransactionScope scope = new TransactionScope .Required))
{
//调用必要的DAL方法
scope.Complete();
}

有没有更好的方法来实现BLL的事务?

解决方案

如果你谈论SQL Server作为后端,它取决于服务器版本。以下是一篇很好的文章: DO.NET和System.Transactions

我引用:


TransactionScope足够聪明
一个完全分配的
交易,其所有的开销
,除非有必要。如果事务
中涉及的
资源是不稳定的,则一切将保留在
内存中,而Microsoft分布式
事务协调器(DTC)不会涉及
。如果资源是与SQL Server 2005的
连接,则不会涉及DTC
,并且SQL Server
2005将处理事务。这个
相当于打开一个内部的
SQL事务。如果SQL Server 2000是
,它将解析为使用完整的
DTC事务。



I'am using enterprise library data access block in my asp.net application. I want to implement transaction from the Business logic layer, across multiple stored procs. Entlib opens a new connection for database access. Does using Transaction Scope in the following way lead to distributed transaction?

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
    // calling necessary DAL methods
   scope.Complete();
}  

Is there better methods to implement transaction from BLL?

解决方案

If you're talking about SQL Server as the backend, it depends on the server version. Here is a good article: DO.NET and System.Transactions

I quote:

The TransactionScope is smart enough not to create a fully distributed transaction with all of its overhead unless it is necessary. If the resource involved in the transaction is volatile, everything will stay in memory and the Microsoft distributed transaction coordinator (DTC) will not be involved. If the resource is a connection to SQL Server 2005, the DTC will not be involved, and SQL Server 2005 will handle the transaction. This is equivalent to opening an internal SQL transaction. If SQL Server 2000 is used, it will resolve to using a full DTC transaction.

这篇关于如何在业务逻辑层中实现事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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