How To Implement transaction in Business logic layer

◇◆丶佛笑我妖孽 提交于 2019-12-07 11:17:37

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/4710390/how-to-implement-transaction-in-business-logic-layer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!