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. Transactions in a stored procedure

Transactions in a stored procedure

Scheduled Pinned Locked Moved Database
sharepointdatabasehelp
3 Posts 3 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.
  • G Offline
    G Offline
    gauthee
    wrote on last edited by
    #1

    Hi, I have a sp where in few values would be passed as input parameters, now using these values insertion opertion should be done for 11 tables. Now if anyone insert statement fails it need not perform the remaining insert statements. What i've done: begin transaction insert insert insert insert... .... ... 11statements total if(@@error<>0) rollback transaction else commit transaction Is this correct! this is leading to some problems, like other users if trying to use any of the tables i used it is giving errors

    Gautham

    J A 2 Replies Last reply
    0
    • G gauthee

      Hi, I have a sp where in few values would be passed as input parameters, now using these values insertion opertion should be done for 11 tables. Now if anyone insert statement fails it need not perform the remaining insert statements. What i've done: begin transaction insert insert insert insert... .... ... 11statements total if(@@error<>0) rollback transaction else commit transaction Is this correct! this is leading to some problems, like other users if trying to use any of the tables i used it is giving errors

      Gautham

      J Offline
      J Offline
      joon vh
      wrote on last edited by
      #2

      it seems correct to me, I always use

      	IF @@ERROR <> 0
      	BEGIN
      		ROLLBACK TRANSACTION TRANS
      	END
      
      	COMMIT TRANSACTION TRANS
      

      Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

      1 Reply Last reply
      0
      • G gauthee

        Hi, I have a sp where in few values would be passed as input parameters, now using these values insertion opertion should be done for 11 tables. Now if anyone insert statement fails it need not perform the remaining insert statements. What i've done: begin transaction insert insert insert insert... .... ... 11statements total if(@@error<>0) rollback transaction else commit transaction Is this correct! this is leading to some problems, like other users if trying to use any of the tables i used it is giving errors

        Gautham

        A Offline
        A Offline
        andyharman
        wrote on last edited by
        #3

        The value of @@ERROR is reset after every SQL statement. You should either use the new SQL-Server 2005 Try-Catch mechanism, or have checks on @@ERROR after each of your insert statements (in which case I would normally use a GOTO to jump to a rollback at the end of the procedure). What errors are you getting?

        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