Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 transaction didn't seem to rollback?

Author  Topic 

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2005-10-05 : 17:19:08
My stored procedure is a very lenghy one, here is a summary of how it works:


CREATE PROCEDURE XXXXXXXXXXX


...


AS


DECLARE @blah INT
..
..

BEGIN TRAN

IF(@blah = 1)
BEGIN

..
..
..
END
ELSE
BEGIN


SELECT ..

UPDATE ...


EXEC SOMESTOREDPROCEDURE @blah <-- ******there was an error in this sproc
END


COMMIT TRAN


---------------


The *** is where the sproc reported the error, I had misspelled a table and therefore from what I ASSUME is that the entire sproc should have rolled back...but it didn't. An insert had taken place in one of the tables.

why did the transaction not rollback? the commit tran was reached but only after an error had occured?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-10-05 : 17:22:31
After each and every single DML operation (INSERT, UPDATE, DELETE), you need to check the value of @@ERROR to determine whether or not to commit/rollback/continue on down the stored procedure. It doesn't appear that you have done this.

Tara
Go to Top of Page

sql777
Constraint Violating Yak Guru

314 Posts

Posted - 2005-10-05 : 17:36:58
no i haven't, ok I wish there was a way to just have it rollback the entire sproc! oh well...
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-10-06 : 04:08:27
It can be quite hard to "catch" an error in a called sub-procedure.

You might want to put

SET XACT_ABORT ON

at the top of your SProcs to force them to abort (won't solve the underlying "catch" problem, but should cause an SProc to abort if you miss checking an @@ERROR somewhere!)

Kristen
Go to Top of Page
   

- Advertisement -