Rolling back already commited data..?

  • Got this email from one of the devs...

    Not sure if you can help with this? I’m writing some Unit Tests to verify the Workflow process. I initially have my Deposit Application wrapped in a Transaction. The problem is that at some points in the code, the Workflow will create a new Connection and Transaction and cannot read to update the uncommitted records in the initial Transaction.

    What I will most likely have to do is commit the “Test” Deposit Application so I can pass it to the Workflow process. The problem is that now I have to clean up the Workflow database to remove the “Test” Deposit Application. The only way I can think of is to simply delete the records for the “Test” Deposit Application from the database. Can you suggest any other ways that you might be aware of?

  • restore the database to a point prior to when the developer entered the data? or delete the data as he surmised?

    that's the onyl two things i can think of.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Yeah I kinda figured

    thanks man

  • If it's Enterprise or Developer edition, create a database snapshot before, revert to it after.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • The "best" solution depends on how complicated the transaction is. If it's just writing records to a table, then his idea of deleting might be good enough. Or make a copy of the table before, then truncate & repopulate the table. If multiple tables are involved, with parent-child and dependencies, then maybe a restore would be better.

  • Thanks everyone..

  • We bounced this arround in the office and one option would be to allow the second process to READ UNCOMMITED transactions. We are assuming this is a controlled, test environment, and he is looking for particular records.

    Then the he can just roll back the uncommited trans at the end.

    Cheers

    Leo

    Leo
    Nothing in life is ever so complicated that with a little work it can't be made more complicated.

  • intersting Leo....

    can you elaborate?

  • Leo.Miller (8/10/2011)


    We bounced this arround in the office and one option would be to allow the second process to READ UNCOMMITED transactions. We are assuming this is a controlled, test environment, and he is looking for particular records.

    Then the he can just roll back the uncommited trans at the end.

    Cheers

    Leo

    I was wondering about that too .... Never tried it so not sure how/if it would work.

  • krypto69 (8/10/2011)


    intersting Leo....

    can you elaborate?

    Yes.....

    But I assume you want more than this..:-)

    On one connection do the update - This was my test

    begin tran

    update Test1 set First_Name = 'Test1' where ID_Col = 10

    waitfor delay '00:00:20'

    rollback

    On another connection run the query but first set the Transaction Isolation Level.

    SET TRANSACTION ISOLATION LEVEL

    READ UNCOMMITTED

    select * from Test1 where ID_Col = 10

    waitfor delay '00:00:20'

    select * from Test1 where ID_Col = 10

    The first select result was as expected, 'Test1'. but after the 20 seconds the value was rolled back.

    As long as he can setup the second set of queries to set the TIL this should work.

    Actually it's quite a sweet solution. I wish I'd thought of it myself.

    Cheers

    Leo

    Leo
    Nothing in life is ever so complicated that with a little work it can't be made more complicated.

  • Another solution would be to set all the queries to use WITH (NOLOCK)

    select * from Test1 with (nolock) where ID_Col = 10

    But I would consider this a bit of a dirty solution, and if there are a lot of queries it may take a while to update them all.

    Leo

    Leo
    Nothing in life is ever so complicated that with a little work it can't be made more complicated.

  • Leo.Miller (8/10/2011)


    Another solution would be to set all the queries to use WITH (NOLOCK)

    select * from Test1 with (nolock) where ID_Col = 10

    But I would consider this a bit of a dirty solution, and if there are a lot of queries it may take a while to update them all.

    Leo

    How is READ UNCOMMITED any less dirty than NOLOCK? Aside from the less code to change point.

  • Ninja's_RGR'us (8/10/2011)


    Leo.Miller (8/10/2011)


    Another solution would be to set all the queries to use WITH (NOLOCK)

    select * from Test1 with (nolock) where ID_Col = 10

    But I would consider this a bit of a dirty solution, and if there are a lot of queries it may take a while to update them all.

    Leo

    How is READ UNCOMMITED any less dirty than NOLOCK? Aside from the less code to change point.

    Personal opinion only, hence my wording.

    Leo

    Leo
    Nothing in life is ever so complicated that with a little work it can't be made more complicated.

  • Ah! Ok, tx.

  • Awesome!

    thanks Leo and please say thank you to everyone that helped...

    good karma to you...

Viewing 15 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic. Login to reply