Error Rolling back inner transaction

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

  • I think you want to use a transaction save point:

    [font="Courier New"]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 [/font]

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

  • 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

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply