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. Web Development
  3. ASP.NET
  4. This SqlTransaction has completed; it is no longer usable

This SqlTransaction has completed; it is no longer usable

Scheduled Pinned Locked Moved ASP.NET
databasehelpcsharpasp-netsql-server
7 Posts 5 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
    Karan_TN
    wrote on last edited by
    #1

    Currently i m using asp.net 2.0 with sql server 2000 database..

    SqlTransaction trans = null;
    try
    {
    trans = conn.BeginTransaction();
    sqlCmd = new SqlCommand("UPDATE tble SET col1=null", conn);
    sqlCmd.Transaction = trans;
    sqlCmd.ExecuteNonQuery();
    sqlCmd.Dispose();
    trans.Commit();
    Response.Redirect("NewInc.aspx");
    }
    catch
    {
    trans.Rollback();
    throw;
    }

    while executing the above coding all executing correctly but at the time of

    response.redirect

    , its throwing the error.. help me. -Karan

    S A C 3 Replies Last reply
    0
    • K Karan_TN

      Currently i m using asp.net 2.0 with sql server 2000 database..

      SqlTransaction trans = null;
      try
      {
      trans = conn.BeginTransaction();
      sqlCmd = new SqlCommand("UPDATE tble SET col1=null", conn);
      sqlCmd.Transaction = trans;
      sqlCmd.ExecuteNonQuery();
      sqlCmd.Dispose();
      trans.Commit();
      Response.Redirect("NewInc.aspx");
      }
      catch
      {
      trans.Rollback();
      throw;
      }

      while executing the above coding all executing correctly but at the time of

      response.redirect

      , its throwing the error.. help me. -Karan

      S Offline
      S Offline
      Sachin Dubey
      wrote on last edited by
      #2

      what actually the error is?? Ithink You Write it InCorrectly You Write Response.Redirect("~/NewInc.aspx");

      K 1 Reply Last reply
      0
      • S Sachin Dubey

        what actually the error is?? Ithink You Write it InCorrectly You Write Response.Redirect("~/NewInc.aspx");

        K Offline
        K Offline
        Karan_TN
        wrote on last edited by
        #3

        the error is : This SqlTransaction has completed; it is no longer usable and its a simple redirect page command.. but its getting error at that page.. but all executions are happening perfectly. but its not getting redirected..... guide me plz - Karan

        C 1 Reply Last reply
        0
        • K Karan_TN

          the error is : This SqlTransaction has completed; it is no longer usable and its a simple redirect page command.. but its getting error at that page.. but all executions are happening perfectly. but its not getting redirected..... guide me plz - Karan

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Have you tried moving the redirect outside the try/catch ?

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          1 Reply Last reply
          0
          • K Karan_TN

            Currently i m using asp.net 2.0 with sql server 2000 database..

            SqlTransaction trans = null;
            try
            {
            trans = conn.BeginTransaction();
            sqlCmd = new SqlCommand("UPDATE tble SET col1=null", conn);
            sqlCmd.Transaction = trans;
            sqlCmd.ExecuteNonQuery();
            sqlCmd.Dispose();
            trans.Commit();
            Response.Redirect("NewInc.aspx");
            }
            catch
            {
            trans.Rollback();
            throw;
            }

            while executing the above coding all executing correctly but at the time of

            response.redirect

            , its throwing the error.. help me. -Karan

            A Offline
            A Offline
            Abhishek Sur
            wrote on last edited by
            #5

            Are you talking about ThreadAbortException... Both Response.Redirect and Server.Transfer creates a new Thread and terminates the Current Thread by calling Thread.Abort and redirects the Response stream to new thread. Thus It generates a First chance ThreadAbortException. If you call Response.Redirect(url,false) it will not throw the first chance exception as it will skip the call to Response.End in the current thread. so your code should be

            SqlTransaction trans = null;
            try
            {
            trans = conn.BeginTransaction();
            sqlCmd = new SqlCommand("UPDATE tble SET col1=null", conn);
            sqlCmd.Transaction = trans;
            sqlCmd.ExecuteNonQuery();
            sqlCmd.Dispose();
            trans.Commit();
            Response.Redirect("NewInc.aspx", false);
            }
            catch
            {
            trans.Rollback();
            throw;
            }

            I hope this help you. :)

            Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


            My Latest Articles-->** Microsoft Bing MAP using Javascript
            CLR objects in SQL Server 2005
            Uncommon C# Keywords
            /xml>

            K 1 Reply Last reply
            0
            • A Abhishek Sur

              Are you talking about ThreadAbortException... Both Response.Redirect and Server.Transfer creates a new Thread and terminates the Current Thread by calling Thread.Abort and redirects the Response stream to new thread. Thus It generates a First chance ThreadAbortException. If you call Response.Redirect(url,false) it will not throw the first chance exception as it will skip the call to Response.End in the current thread. so your code should be

              SqlTransaction trans = null;
              try
              {
              trans = conn.BeginTransaction();
              sqlCmd = new SqlCommand("UPDATE tble SET col1=null", conn);
              sqlCmd.Transaction = trans;
              sqlCmd.ExecuteNonQuery();
              sqlCmd.Dispose();
              trans.Commit();
              Response.Redirect("NewInc.aspx", false);
              }
              catch
              {
              trans.Rollback();
              throw;
              }

              I hope this help you. :)

              Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


              My Latest Articles-->** Microsoft Bing MAP using Javascript
              CLR objects in SQL Server 2005
              Uncommon C# Keywords
              /xml>

              K Offline
              K Offline
              Karan_TN
              wrote on last edited by
              #6

              excellent Abhishek Sur!! :-D this solves my problem..... CodeProject rocks !!

              1 Reply Last reply
              0
              • K Karan_TN

                Currently i m using asp.net 2.0 with sql server 2000 database..

                SqlTransaction trans = null;
                try
                {
                trans = conn.BeginTransaction();
                sqlCmd = new SqlCommand("UPDATE tble SET col1=null", conn);
                sqlCmd.Transaction = trans;
                sqlCmd.ExecuteNonQuery();
                sqlCmd.Dispose();
                trans.Commit();
                Response.Redirect("NewInc.aspx");
                }
                catch
                {
                trans.Rollback();
                throw;
                }

                while executing the above coding all executing correctly but at the time of

                response.redirect

                , its throwing the error.. help me. -Karan

                C Offline
                C Offline
                carlecomm
                wrote on last edited by
                #7

                Hi, you can try moving trans.Rollback() and Response.Redirect("NewInc.aspx") to 'finally' block.

                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