Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3789876
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:13:36+00:00 2026-05-19T12:13:36+00:00

I have needs to keep some of log data in different tables even my

  • 0

I have needs to keep some of log data in different tables even my transaction is rolled back.

I already learned that in SQL Server it is impossible do something like this

begin tran t1
insert ...
insert ...
select ...
       begin tran t2
         insert into log
       commit tran t2
rollback tran t1
select * from log -- IS EMPTY ALWAYS

So I try hacking SQL Server that I madded CLR which is going to export data need for LOG to local server disk in XML format. CLR Code is simple as it can be:

File.WriteAllText(fileName, xmlLog.Value.ToString());

Before I release this in production bases Ill love to hear your toughs about this technique.

Here are few questions:

  • Is there other better way to accomplish autonomous transaction in SQL Server 2005
  • How can be bad holding my transaction uncommitted while SQL Server is executing CLR (amount of data written by SQL is relative small about 50 – 60 records of 3 integers and 4 floats)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:13:37+00:00Added an answer on May 19, 2026 at 12:13 pm

    I would suggest using a Table Variable as it is not affected by the Transaction (this is one of the methods listed in the blog noted by Martin below the question). Consider doing this, which will work in SQL Server 2005:

    DECLARE @TempLog TABLE (FieldList...)
    
    BEGIN TRY
    
        BEGIN TRAN
    
        INSERT...
    
        INSERT INTO @TempLog (FieldList...) VALUES (@Variables or StaticValues...)
    
        INSERT...
    
        INSERT INTO @TempLog (FieldList...) VALUES (@Variables or StaticValues...)
    
        COMMIT TRAN
    
    END TRY
    BEGIN CATCH
    
        IF (@@TRANCOUNT > 0)
        BEGIN
            ROLLBACK TRAN
        END
    
        /* Maybe add a Log message to note that we ran into an error */
        INSERT INTO @TempLog (FieldList...) VALUES (@Variables or StaticValues...)
    
    END CATCH
    
    INSERT INTO RealLogTable (FieldList...)
        SELECT FieldsList
        FROM @TempLog
    

    Please note that while we are making use of the fact that Table Variables are not part of the transaction, that does create a potential situation where this code does a COMMIT but errors (or server crashes) before the INSERT INTO RealLogTable and you will have lost the logging for the data that did make it in. At this point there would be a disconnect as there is data but no record of it being inserted as far as RealLogTable is concerned. But this is just the obvious trade-off for being able to bypass the Transaction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data that needs to be executed on a certain background thread. I
I have a thread that needs to write data from an in-memory buffer to
I have a form action that needs to have its value set from a
I have a field in my report that needs to have a length of
I'm writing a stored procedure that needs to have a lot of conditioning in
I recently inherited a VBA macro that needs to have validation logic added to
I have an app that needs to open a new window (in the same
When I have two mysql servers that have different jobs (holding different databases) but
I'm having some trouble figuring this out. I have a script that checks a
I have a binary log file with streaming data from a sensor (Int16). Every

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.