I have this specific DAO that inherits methods from a generic DAO I would like to add a transaction to this code in order to roll back all changes that where made if an exception is found
TDAO tDAO = new TDAO();
TDAO2 tDAO2 = new TDAO2();
//Get the DAO to delete from the database let's call them dDao and dDao2
//Start the Transaction
using (TransactionScope trans = new TransactionScope())
{
try
{
//Delete all SGC Associated switch
TDAO2.Delete(dDao);
//Delete switch
TDAO.Delete(dDao2);
//send notification
base.SendChangeNotification();
//Commit the Information Completing the Transaction
trans.Complete();
}
catch (UpdateException ex)//SQL exception
{
//Log the error
//Rollback the changes if there is an exception
throw new Exception(Resources.ErrorMessages.OperationNotPermited);
}
catch (Exception ex) //Other exception
{
//Log the error
throw new Exception(Resources.ErrorMessages.UndifenedError);
}
}
In Visual Studio, go to the References icon in your project. Right-click, Add Reference. Then search for System.Transactions.dll. Select it, click Ok. Then try rebuilding your project. Also make sure you have either a Using statement (C#) or Imports statement (VB) at the top, something like Using System.Transactions;
And the Changes are in the code . Thank You