CLR Trigger Rollback

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.
 
P

Pablo Castro [MS]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top