Managing Transactions with a Stack
public void BeginTransaction()
{
SqlTransaction currentTrans = currentConnection.BeginTransaction();
transactions.Push(currentTrans);
}
public void RollbackTransaction()
{
SqlTransaction currentTrans;
while (transactions.Count > 0)
{
currentTrans = (SqlTransaction)transactions.Pop();
currentTrans.Rollback();
}
}
public void CommitTransaction()
{
SqlTransaction currentTrans = (SqlTransaction)transactions.Peek();
currentTrans.Commit();
transactions.Pop();
}
public SqlTransaction CurrentTransaction
{
get
{
if (transactions.Count > 0)
return (SqlTransaction)transactions.Peek();
else
return null;
}
}
I have the transactions variable declared as:
private Stack transactions = new Stack();
No comments:
Post a Comment