cancel
Showing results for 
Search instead for 
Did you mean: 

What's an MSS 2008 equivalent for MESSAGE TO CONSOLE?

Breck_Carter
Participant
3,494

How do I write diagnostic/trace messages to a text file during the execution of a stored procedure on Microsoft SQL Server 2008, similar to SQL Anywhere's MESSAGE ... TO CONSOLE statement?

I need this facility to help diagnose and test MSS stored procedures called from MobiLink scripts.

Accepted Solutions (1)

Accepted Solutions (1)

MCMartin
Participant

you could use something like this, written by Narayana Vyas Kondreddi:

SET NOCOUNT ON
DECLARE @execstr VARCHAR(255)
SET @execstr = RTRIM('echo ' + COALESCE(LTRIM(@msg),'-') + CASE WHEN (@overwrite = 1) THEN ' > ' ELSE ' >> ' END + RTRIM(@file))
EXEC master..xp_cmdshell @execstr
SET NOCOUNT OFF

or use instead

xp_logevent { error_number , 'message' } [ , 'severity' ]

to log to the event log

Answers (1)

Answers (1)

VolkerBarth
Contributor

I would use RAISERROR ... WITH LOG to write to the current SQL Server error log file, cf.

raiserror('Volker''s test message', 0, 1) with log

I guess RAISERROR with a low severity (0-10, 0 in this case) should not interfere with the execution of the stored procedure as they should be treated as information/warning, not as a real error.

That being said, SQL Anywhere's MESSAGE statement seems so much easier to understand and use. But that's a fact you do already know:)