Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Error Rolling back inner transaction


Error Rolling back inner transaction

Author
Message
presidencyprakash
presidencyprakash
Valued Member
Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)

Group: General Forum Members
Points: 54 Visits: 37
Hi,

When i execute the following Script.
I get error 'Cannot roll back InnerTran. No transaction or savepoint of that name was found.'
i.e I couldn't able to rollback inner transaction.
Can any one know the reason for this?

Create Table BPTest(id int)
begin try
begin tran OuterTran
Insert into BPTest values (1)
begin try
begin tran InnerTran
Insert into BPTest values (2)
Declare @Error varchar(500)
set @Error='test'
RAISERROR(@Error, 16, -1)
commit tran InnerTran
end try
begin catch
rollback tran InnerTran
end catch
Insert into BPTest values (3)
rollback tran OuterTran
end try
begin catch
print Error_Message()
end catch
Select * from BPTest
drop table BPTest

Thanks in advance,
Regards,
B. Prakash

To Get Succeeded in Life don't get Changed according to the environment,

Be Honest, Smart & Bold enough to create your own fine environment.

Regards,
B.Prakash.
Michael Earl-395764
Michael Earl-395764
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3029 Visits: 23078
I think you want to use a transaction save point:

Create Table #BPTest(id int)
begin try
begin tran OuterTran
Insert into #BPTest values (1)
begin try
save tran InnerTran
Insert into #BPTest values (2)
Declare @Error varchar(500)
set @Error='test'
RAISERROR(@Error, 16, -1)
end try
begin catch
rollback tran InnerTran
end catch
Insert into #BPTest values (3)
end try
begin catch
print Error_Message()
rollback tran OuterTran
end catch
Select * from #BPTest
drop table #BPTest

nazir_ahmed
nazir_ahmed
Grasshopper
Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)Grasshopper (19 reputation)

Group: General Forum Members
Points: 19 Visits: 38
So we cannot have nested Transactions (it does not make any sense to have nested transaction when we are not allowed to rollback the inner transaction) in SQL Server? And if we want nested transaction we should use Save Point instead?

In other words in SQL Server nested transactions can be implemented by using Save Points? Kindly explain this.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (54K reputation)SSC Guru (54K reputation)SSC Guru (54K reputation)SSC Guru (54K reputation)SSC Guru (54K reputation)SSC Guru (54K reputation)SSC Guru (54K reputation)SSC Guru (54K reputation)

Group: General Forum Members
Points: 54977 Visits: 44680
Nested transactions are a lie.
http://sqlskills.com/BLOGS/PAUL/post/A-SQL-Server-DBA-myth-a-day-%282630%29-nested-transactions-are-real.aspx

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search