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. General Programming
  3. C#
  4. SqlTransaction Rollback

SqlTransaction Rollback

Scheduled Pinned Locked Moved C#
database
8 Posts 4 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.
  • N Offline
    N Offline
    Navneet Hegde
    wrote on last edited by
    #1

    Hi, I am using a block of code to Import the Data to SQLServer2000

    try
    sqlTransaction sqlTran;
    {
    using (sqlTran = MyConnnection.BeginTansaction )
    try
    {
    ImportData();
    sqlTran.Commit();
    }
    catch(Exception ex)
    {
    sqlTran.Rollback()
    }
    }
    catch
    {}

    Now as the Process start's If in middle of the Process I close the Window the Process stop's, But the related tables in DB doesn't respond Is that because rollback() is not called.If yes then Is it possible to calls Rollback in such situation. Thanks Navneet Hegde

    Develop2Program & Program2Develop

    A P 2 Replies Last reply
    0
    • N Navneet Hegde

      Hi, I am using a block of code to Import the Data to SQLServer2000

      try
      sqlTransaction sqlTran;
      {
      using (sqlTran = MyConnnection.BeginTansaction )
      try
      {
      ImportData();
      sqlTran.Commit();
      }
      catch(Exception ex)
      {
      sqlTran.Rollback()
      }
      }
      catch
      {}

      Now as the Process start's If in middle of the Process I close the Window the Process stop's, But the related tables in DB doesn't respond Is that because rollback() is not called.If yes then Is it possible to calls Rollback in such situation. Thanks Navneet Hegde

      Develop2Program & Program2Develop

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

      Try putting the rollback and commit in a FINALLY block and set an indicator so you know which to execute. FINALLY blocks are always executed.

      Bob Ashfield Consultants Ltd

      N P 2 Replies Last reply
      0
      • A Ashfield

        Try putting the rollback and commit in a FINALLY block and set an indicator so you know which to execute. FINALLY blocks are always executed.

        Bob Ashfield Consultants Ltd

        N Offline
        N Offline
        Navneet Hegde
        wrote on last edited by
        #3

        Thanks So, if I close my Application through Task maNager, Then before ending the process FINALLY will be executed.

        Develop2Program & Program2Develop

        L A 2 Replies Last reply
        0
        • N Navneet Hegde

          Thanks So, if I close my Application through Task maNager, Then before ending the process FINALLY will be executed.

          Develop2Program & Program2Develop

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          I doubt that! Why on earth do you want to close the application through the Task Manager?

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          N 1 Reply Last reply
          0
          • L leppie

            I doubt that! Why on earth do you want to close the application through the Task Manager?

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)

            N Offline
            N Offline
            Navneet Hegde
            wrote on last edited by
            #5

            :) anyway!! I wanted to be sure that my DB is not hanged in case of any eventuality.So Rollback is fired atleast.

            Develop2Program & Program2Develop

            1 Reply Last reply
            0
            • N Navneet Hegde

              Thanks So, if I close my Application through Task maNager, Then before ending the process FINALLY will be executed.

              Develop2Program & Program2Develop

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

              Maybe. Put something like writing a file in the finally (so you know for sure) and try it.

              Bob Ashfield Consultants Ltd

              1 Reply Last reply
              0
              • N Navneet Hegde

                Hi, I am using a block of code to Import the Data to SQLServer2000

                try
                sqlTransaction sqlTran;
                {
                using (sqlTran = MyConnnection.BeginTansaction )
                try
                {
                ImportData();
                sqlTran.Commit();
                }
                catch(Exception ex)
                {
                sqlTran.Rollback()
                }
                }
                catch
                {}

                Now as the Process start's If in middle of the Process I close the Window the Process stop's, But the related tables in DB doesn't respond Is that because rollback() is not called.If yes then Is it possible to calls Rollback in such situation. Thanks Navneet Hegde

                Develop2Program & Program2Develop

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                If the application terminates unexpectedly the connection will be closed and any transaction will be rolled back.

                1 Reply Last reply
                0
                • A Ashfield

                  Try putting the rollback and commit in a FINALLY block and set an indicator so you know which to execute. FINALLY blocks are always executed.

                  Bob Ashfield Consultants Ltd

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  Ashfield wrote:

                  FINALLY blocks are always executed.

                  Not if the application is terminated outside its control, though I don't know why he's concerned about it.

                  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