Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Transaction Problem

SQL Transaction Problem

Scheduled Pinned Locked Moved Database
helpdatabase
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kaushal Arora
    wrote on last edited by
    #1

    I have a procedure running with transaction used in it. I have used multiple insert in the procedures and finally return the scope_identity() of one of the insert by first setting a variable with scope_identity() and then returning it with select @variable at the end of procedure after commit and in case of RollBack i m returning it as select -9 The issue what am i facing is that sometimes it is skipping the return value in case of Commit Transaction as it is not returning anything to the code. I am using it like this:

    Full Procedure Code with Insert Commands here

    set @variable=scope_identity()

    IF @@ERROR <> 0
    BEGIN
    -- Rollback the transaction
    ROLLBACK

    Select -9
    

    END

    COMMIT

    select @variable

    The procedure is not going in the @@ERROR section and also all the insert values are there in tables after commit but why sometimes it is not returning the value required. I am using ExecuteScaler in the code. Regards, Kaushal Arora Regards, Kaushal Arora

    A 1 Reply Last reply
    0
    • K Kaushal Arora

      I have a procedure running with transaction used in it. I have used multiple insert in the procedures and finally return the scope_identity() of one of the insert by first setting a variable with scope_identity() and then returning it with select @variable at the end of procedure after commit and in case of RollBack i m returning it as select -9 The issue what am i facing is that sometimes it is skipping the return value in case of Commit Transaction as it is not returning anything to the code. I am using it like this:

      Full Procedure Code with Insert Commands here

      set @variable=scope_identity()

      IF @@ERROR <> 0
      BEGIN
      -- Rollback the transaction
      ROLLBACK

      Select -9
      

      END

      COMMIT

      select @variable

      The procedure is not going in the @@ERROR section and also all the insert values are there in tables after commit but why sometimes it is not returning the value required. I am using ExecuteScaler in the code. Regards, Kaushal Arora Regards, Kaushal Arora

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      You are not setting your variable: set @variable=scope_identity() IF @@ERROR <> 0 BEGIN -- Rollback the transaction ROLLBACK Select **@variable =** -9 END COMMIT select @variable

      Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

      K 1 Reply Last reply
      0
      • A Ashfield

        You are not setting your variable: set @variable=scope_identity() IF @@ERROR <> 0 BEGIN -- Rollback the transaction ROLLBACK Select **@variable =** -9 END COMMIT select @variable

        Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

        K Offline
        K Offline
        Kaushal Arora
        wrote on last edited by
        #3

        I am saying it is committing the records not giving any error and rollback. It is not returning the value in case of committing the records.

        A 1 Reply Last reply
        0
        • K Kaushal Arora

          I am saying it is committing the records not giving any error and rollback. It is not returning the value in case of committing the records.

          A Offline
          A Offline
          Ashfield
          wrote on last edited by
          #4

          Without the rest of your code its kinda hard to say then.

          Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups