CLR Trigger Rollback

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I setup a CLR trigger to rollback the transaction that fired the
trigger if an exception occurs.
Here is waht I'm trying to do
SQL:
INSERT INTO myTable(column1, column2)
Values(1, 2)
C# Trigger:
....
try
{
//do some processing
}
catch (SqlException ex)
{
//rollback the insert statement
}
....
I have seen code like this SqlContext.GetTransaction().Rollback however this
seems to have benn written on one of the betas because the SqlContext does
not have a GetTransaction method in the final version.
 
Try:

System.Transactions.Transaction.Current.Rollback();

That should do it for your scenario.

--
Pablo Castro
Program Manager - ADO.NET Team
Microsoft Corp.

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top