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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. T-SQL: How to force rows insertion ignoring transactions?

T-SQL: How to force rows insertion ignoring transactions?

Scheduled Pinned Locked Moved Database
databasetutorialquestion
5 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.
  • Y Offline
    Y Offline
    Yuval Naveh
    wrote on last edited by
    #1

    Hi, I have a logger written in T-SQL (Stored Procs) writing to a log table. When there are exceptions a log row is written, but then when the outer transaction rolls back it also rolls back the log entry. I would like to have the log entry (i.e. row) to be inserted and persisted regardless of what the outer (nested) transactions are doing. The log entry should never roll back Could someone point me to a solution using T-SQL? Thanks Yuval

    "The true sign of intelligence is not knowledge but imagination." - Albert Einstein

    L D 2 Replies Last reply
    0
    • Y Yuval Naveh

      Hi, I have a logger written in T-SQL (Stored Procs) writing to a log table. When there are exceptions a log row is written, but then when the outer transaction rolls back it also rolls back the log entry. I would like to have the log entry (i.e. row) to be inserted and persisted regardless of what the outer (nested) transactions are doing. The log entry should never roll back Could someone point me to a solution using T-SQL? Thanks Yuval

      "The true sign of intelligence is not knowledge but imagination." - Albert Einstein

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Yuval Naveh wrote:

      I would like to have the log entry (i.e. row) to be inserted and persisted regardless of what the outer (nested) transactions are doing. The log entry should never roll back Could someone point me to a solution using T-SQL?

      You could use a raiserror[^] to write your message to the sys.messages view. You'd have to predefine the errormessages using sp_addmessage though. Alternatively, if it's from a stored procedure then you might choose to add them to a variable, as opposed to logging them immediately. Next, RETURN that variable when exiting the sproc, and write insert it's contents to the logfile loggingtable. If you have the option to drop the TSQL-requirement, then go for extended procedures, like xp_cmdshell (executing isql.exe to execute an SQL statement). I hope someone else comes up with something better :)

      I are Troll :suss:

      modified on Tuesday, January 19, 2010 7:31 PM

      Y 1 Reply Last reply
      0
      • Y Yuval Naveh

        Hi, I have a logger written in T-SQL (Stored Procs) writing to a log table. When there are exceptions a log row is written, but then when the outer transaction rolls back it also rolls back the log entry. I would like to have the log entry (i.e. row) to be inserted and persisted regardless of what the outer (nested) transactions are doing. The log entry should never roll back Could someone point me to a solution using T-SQL? Thanks Yuval

        "The true sign of intelligence is not knowledge but imagination." - Albert Einstein

        D Offline
        D Offline
        debrah h48
        wrote on last edited by
        #3

        Check out quires here. http://technet.microsoft.com/en-us/library/ms187373.aspx[^]

        Y 1 Reply Last reply
        0
        • L Lost User

          Yuval Naveh wrote:

          I would like to have the log entry (i.e. row) to be inserted and persisted regardless of what the outer (nested) transactions are doing. The log entry should never roll back Could someone point me to a solution using T-SQL?

          You could use a raiserror[^] to write your message to the sys.messages view. You'd have to predefine the errormessages using sp_addmessage though. Alternatively, if it's from a stored procedure then you might choose to add them to a variable, as opposed to logging them immediately. Next, RETURN that variable when exiting the sproc, and write insert it's contents to the logfile loggingtable. If you have the option to drop the TSQL-requirement, then go for extended procedures, like xp_cmdshell (executing isql.exe to execute an SQL statement). I hope someone else comes up with something better :)

          I are Troll :suss:

          modified on Tuesday, January 19, 2010 7:31 PM

          Y Offline
          Y Offline
          Yuval Naveh
          wrote on last edited by
          #4

          Hi Eddy, Using the xp_cmdshell to come back and insert rows is a possibility - looks a bit cumbersome though. If I can't figure it out a more elegant way this might be a (temporary) solution. Thanks, Yuval

          "The true sign of intelligence is not knowledge but imagination." - Albert Einstein

          1 Reply Last reply
          0
          • D debrah h48

            Check out quires here. http://technet.microsoft.com/en-us/library/ms187373.aspx[^]

            Y Offline
            Y Offline
            Yuval Naveh
            wrote on last edited by
            #5

            Hi, I could not find a specific hint that solves the problem. Thanks Yuval

            "The true sign of intelligence is not knowledge but imagination." - Albert Einstein

            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