You could try using the TransactionScope class from .NET 2.0 s System.Transactions namespace. This class allows you to specify a timeout after which the transaction will automatically be cancelled and rolled back. ADO.NET in .NET 2.0+ is TransactionScope aware, and will automatically enroll a DbTransaction in the scope if one is present at the time the database is called:
public void DoSomething()
{
using (TransactionScope scope = new TransactionScope(TransactionScopeOptions.Required, TimeSpan.FromSeconds(60)))
{
MyDac();
scope.Complete(); // If timeout occurrs, this line is never hit, scope is disposed, which causes rollback if Complete() was not called
}
}
public class MyDac()
{
using (SqlConnection ...)
{
using (SqlCommand ...)
{
// Do something with ADO.NET here...it will autoenroll if a transaction scope is present
}
}
}
交易 范围建立了一个系统。 交易。 内部交易,如果仅涉及一个服务器,则根据违约允许对服务器进行轻重交易。 如果交易涉及多个服务器或分配的资源管理人员,将推动通过交易复印件进行的交易,这将要求贸易与发展协调中心进行协调,从而使交易范围的使用复杂化。 如果你的所有交易都是轻重的,那么,交易复印机可以提供大量好处,而不是手工管理你的 d交易。