Hello
I have the following code which add a company then an employee:
try
{
transactionManager = SqlDataRepository.CreateTransaction();
transactionManager.BeginTransaction();
DataRepository.CompanyProvider.Insert( company );
DataRepository.EmployeeProvider.Insert( employee );
transactionManager.Commit();
}
catch( Exception e )
{
if ( ( transactionManager != null )
&& ( transactionManager.Isopen ) )
{
transactionManager.Rollback();
}
}
what I would like is that the company insert would be rolled back if the employee insert fails.
But I'm not able to do that.
I get the following trace in sql profiler when there is an error during the insert of the employee :
RPC:Completed exec sp_reset_connection
SQL:BatchCompleted SET TRANSACTION ISOLATION LEVEL READ COMMITTED;BEGIN TRANSACTION RPC:Completed exec sp_reset_connection
RPC:Completed exec sp_executesql N' INSERT INTO dbo.[Company]()VALUES()
RPC:Completed exec sp_reset_connection
RPC:Completed exec sp_executesql N' INSERT INTO dbo.[Employee]()VALUES ()
SQL:BatchCompleted IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
Could you explain me what is wrong in my code please ?
Regards