on 2011 May 29 8:02 AM
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.
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
9 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.