sqlcmd returning data as if transaction just committed has not yet happened

  • Hi All

    I am stumped to understand how what I am seeing can be true.

    I have a batch file that runs a sqlcmd against a database.

    The first call takes a long time (it is an upgrade script and so changes tables, SPs, etc) and is in a single transaction. The last thing this does is INSERT a new record in a table which identifies the current version. So version was N abd now a new record is inserted N+1. So MAX(Value) would be N+1.

    The second call simply asks what the MAX(Version) is from this table.

    What I have witnessed is that the first query is called - some time passed until it has finished and then the second quesry occurs but the result from the second query is not N+1 (as expected) but N.

    I am not using any special TRANSACTIONs to my knowledge, like read uncommitted or anything like that.

    What could be happening to see this result?

    This has only occurred on one server - it has workd as expected everywhere else - could it be a server setting - or it is a potential bug in SQL itself?

    Thanks

  • Are you sure the first query completed successfully?

    Sounds as though it's failing before it gets to the bit where it does the N+1 at the end.

  • Yes - it is definitely working.

    The first SP does

    BEGIN TRY

    BEGIN TRANSACTION

    Do stuff

    INSERT record

    COMMIT TRAN

    END TRY

    BEGIN CATCH

    -- handle and rollback

    END CATCH

    The second query returned response as if not worked - but on examination the record is actually there - it all worked fine.

    It just seems that at the split second the second query asked - the record was not there but it is now.

Viewing 3 posts - 1 through 2 (of 2 total)

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