PC Review


Reply
Thread Tools Rate Thread

CLR Trigger Rollback

 
 
=?Utf-8?B?RGF2aWQgUg==?=
Guest
Posts: n/a
 
      6th Dec 2005
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.
 
Reply With Quote
 
 
 
 
Pablo Castro [MS]
Guest
Posts: n/a
 
      8th Dec 2005
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.


"David R" <(E-Mail Removed)> wrote in message
news:AFB8A82E-28A7-437B-8907-(E-Mail Removed)...
> 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.



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CLR Trigger Rollback honzas Microsoft ADO .NET 6 18th Oct 2006 11:52 AM
Rollback transaction doesnt work when DataAdapter.Update() throws exception caused by RAISEERROR in a trigger Mark Vuksani Microsoft Dot NET 5 9th Mar 2004 09:46 PM
Rollback transaction doesnt work when DataAdapter.Update() throws exception caused by RAISEERROR in a trigger Mark Vuksani Microsoft Dot NET Framework 5 9th Mar 2004 09:46 PM
Rollback transaction doesnt work when DataAdapter.Update() throws exception caused by RAISEERROR in a trigger Mark Vuksani Microsoft ADO .NET 5 9th Mar 2004 09:46 PM
Rollback transaction doesnt work when DataAdapter.Update() throws exception caused by RAISEERROR in a trigger Mark Vuksani Microsoft Dot NET Framework Forms 5 9th Mar 2004 09:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:53 AM.