Using raiseerror to flush print-buffer

  • During development (and occasionally for debugging in production) we find it useful to use print-statements. However, the print-statement does not give immediate output, and I believe I once heard that this was because print-outs wait for an output-buffer to be filled?

    We have now discovered that if we do a raiseerror immediately after the print-statement, we will get instant output. Something like this:

    PRINT @my_message   

    RAISEERROR('',-1,-1) with NOWAIT

    Are there any disadvantages or dangers with doing it this way? And are there alternative ways of flushing the output-buffer immediately?

    Any suggestions are welcome.

     

  • Why not just use:

    RAISERROR(@my_message,0,1) with NOWAIT

    I use this in all sorts of tsql scripts and stored procedures in order to get more interactive ressults back. So far I've seen no issues with doing it this way.

    PS: -1 and -1 for severity and state are invalid and would result in RAISERROR using defaults. Sev 0 is the lowest you can go, 1 is the lowest state.

     

    Steve

  • Didn't see the one-line-instead-of-two solution, but I guess I should have.

    Anyway, thanks for the feedback, Steven!

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

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