Discussion:
flushing print output to the query window
(too old to reply)
Brian
2008-02-18 21:48:01 UTC
Permalink
I am using sql server mgmt studio and running scripts/queries that are
taking a very long time so i have print statements inserted at places where I
can tell what is happening. However it seems as though these print statements
are buffered and show up in chunks all at once. is there any way to flush the
console io so that i can see them as they happen instead of when some buffer
fills up and flushes?
Aaron Bertrand [SQL Server MVP]
2008-02-18 21:50:42 UTC
Permalink
Instead of using PRINT use:

RAISERROR('my message', 0, 1) WITH NOWAIT;
Post by Brian
I am using sql server mgmt studio and running scripts/queries that are
taking a very long time so i have print statements inserted at places where I
can tell what is happening. However it seems as though these print statements
are buffered and show up in chunks all at once. is there any way to flush the
console io so that i can see them as they happen instead of when some buffer
fills up and flushes?
Erland Sommarskog
2008-02-18 23:12:27 UTC
Permalink
Post by Aaron Bertrand [SQL Server MVP]
RAISERROR('my message', 0, 1) WITH NOWAIT;
However, beware that Mgmt Studio starts buffering also NOWAIT messages
after 500 messages.

This does not happen with the old Query Analyzer that comes with SQL 2000.
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Aaron Bertrand [SQL Server MVP]
2008-02-19 02:48:47 UTC
Permalink
Post by Erland Sommarskog
Post by Aaron Bertrand [SQL Server MVP]
RAISERROR('my message', 0, 1) WITH NOWAIT;
However, beware that Mgmt Studio starts buffering also NOWAIT messages
after 500 messages.
True, I consider that a frringe case, though. Does it depend on the size of
the text? E.g. if I have 500 tiny messages vs. 500 longer messages?
Erland Sommarskog
2008-02-19 08:41:07 UTC
Permalink
Post by Aaron Bertrand [SQL Server MVP]
True, I consider that a frringe case, though. Does it depend on the
size of the text? E.g. if I have 500 tiny messages vs. 500 longer
messages?
I don't think so. My testing anyway has been with small messages (just a
number), so if it matters, the limit is lower for real messages.

As for being a fringe case, I have been involved with running things where
this have mattered.
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Aaron Bertrand [SQL Server MVP]
2008-02-19 11:02:53 UTC
Permalink
Post by Erland Sommarskog
As for being a fringe case, I have been involved with running things where
this have mattered.
Ah, but you are not normal. :-)
Jeremy A. Holovacs
2008-02-19 12:58:33 UTC
Permalink
Hmm... How does that work with TRY/ CATCH blocks? I must investigate...
Post by Aaron Bertrand [SQL Server MVP]
RAISERROR('my message', 0, 1) WITH NOWAIT;
Post by Brian
I am using sql server mgmt studio and running scripts/queries that are
taking a very long time so i have print statements inserted at places where I
can tell what is happening. However it seems as though these print statements
are buffered and show up in chunks all at once. is there any way to flush the
console io so that i can see them as they happen instead of when some buffer
fills up and flushes?
Aaron Bertrand [SQL Server MVP]
2008-02-19 13:19:08 UTC
Permalink
Post by Jeremy A. Holovacs
Hmm... How does that work with TRY/ CATCH blocks?
The same as it would work anywhere else. You replace PRINT 'your message'
with the syntax I provided.

A
Erland Sommarskog
2008-02-19 22:52:56 UTC
Permalink
Post by Jeremy A. Holovacs
Hmm... How does that work with TRY/ CATCH blocks? I must investigate...
No worry. As the severity level is 0, no error will be raised. In fact,
PRINT is just shorthand for RAISERROR(message, 0, 1) in my opinion.
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Aaron Bertrand [SQL Server MVP]
2008-02-19 23:05:14 UTC
Permalink
Post by Erland Sommarskog
Post by Jeremy A. Holovacs
Hmm... How does that work with TRY/ CATCH blocks? I must investigate...
No worry. As the severity level is 0, no error will be raised. In fact,
PRINT is just shorthand for RAISERROR(message, 0, 1) in my opinion.
Oh, good catch. I didn't presume "work with" actually meant "not trigger
the catch in"...
David Feinberg
2008-03-25 20:04:35 UTC
Permalink
This does not work. I run
PRINT 'before'
RAISERROR ('test', 0, 1) WITH NOWAIT
WAITFOR DELAY '000:00:05'
PRINT 'after'

in sql server 2005 and see no output at all until after the 5 seconds.
in a query window in sql server management studio


*** Sent via Developersdex http://www.developersdex.com ***
Tibor Karaszi
2008-03-25 20:12:09 UTC
Permalink
Do you execute to text in SSMS (as opposed to grid mode)?
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
Post by David Feinberg
This does not work. I run
PRINT 'before'
RAISERROR ('test', 0, 1) WITH NOWAIT
WAITFOR DELAY '000:00:05'
PRINT 'after'
in sql server 2005 and see no output at all until after the 5 seconds.
in a query window in sql server management studio
*** Sent via Developersdex http://www.developersdex.com ***
Aaron Bertrand [SQL Server MVP]
2008-03-27 12:54:15 UTC
Permalink
Make sure you are focused on the "Messages" tab/pane, and not the grid
results. If you execute in results to grid, by default, the grid is in the
forefront, and the messages ARE being written to the Messages pane in real
time, but you can't see them because they are behind the grid.
Post by David Feinberg
This does not work. I run
PRINT 'before'
RAISERROR ('test', 0, 1) WITH NOWAIT
WAITFOR DELAY '000:00:05'
PRINT 'after'
in sql server 2005 and see no output at all until after the 5 seconds.
in a query window in sql server management studio
*** Sent via Developersdex http://www.developersdex.com ***
Alex Kuznetsov
2008-03-27 13:53:25 UTC
Permalink
Post by David Feinberg
This does not work. I run
PRINT 'before'
RAISERROR ('test', 0, 1) WITH NOWAIT
WAITFOR DELAY '000:00:05'
PRINT 'after'
in sql server 2005 and see no output at all until after the 5 seconds.
in a query window in sql server management studio
*** Sent via Developersdexhttp://www.developersdex.com***
Press Ctrl+T to switch to text mode

Loading...