0

I have created a SQLAgent Job and one of the job steps executes a procedure which is not under my direct control. The procedure has print statements in it and when it is executed, the output of all these print statement shows up under Job History->Log File summary->row details pane as a Message. This by itself is not an issue but these message obscure an error which can sometimes occur. How do I configure the SQLAgent (or the job step) such that it ignores these (informational) messages and only show error messages. Step to repro : Create a job step which has the statement : print 'hello world' and execute the job step. The history shows Message Executed as user: NT SERVICE\SQLAgent$MSSQLSERVER2019. hello world [SQLSTATE 01000] (Message 0). The step succeeded. Now if they are a series of these print statements amongst a SQL statement whose execution results in a divide-by-zero error, it will show up as a Message but it will be obscured by all these print statement outputs. But if these informational message can be suppressed, the error message will be easily visible.

1 Answer 1

1

The procedure has print statements in it and when it is executed, the output of all these print statement shows up under Job History->Log File summary->row details pane as a Message.

How do suppress informational messages generated by a SQLAgent job step?

I don't believe it's possible unfortunately. These aren't a specific category of messages, rather they're just output from the procedure that was executed.

What you can do instead, to improve your traceability on errors, is capture the full output / message to a separate source that isn't limited in character length, so that it doesn't get truncated.

Relevant info from Kin Shah for historical reference purposes:

You can achieve it in 2 ways - Go in job step and select the Advanced tab:

a. Output to a file (<== My preferred method)

Output to a File

b. "Log to table" and "Include step output in history" (<== You need to trim msdb..sysjobhistory in long-run as the messages are stored as nvarchar(max) instead of nvarchar(1024))

Log to Table

In order to see the additional logged information you need to use this stored procedure sp_help_jobsteplog or you could query the msdb.dbo.sysjobstepslogs table directly.

What this does is log the full message to another place than the default table msdb.dbo.sysjobhistory which has a character limit.

More information as per Kin's aforementioned answer.

3
  • This does not appear to suppress any print output. Does anything else need to be done in addition to Checking the Log To Table and Include setup output in history ?
    – QFirstLast
    Commented Feb 13, 2023 at 8:30
  • @QFirstLast As I first said "I don't believe it's possible unfortunately". But doing this will get you the full messages so any errors don't get obscured.
    – J.D.
    Commented Feb 13, 2023 at 13:40
  • Thanks @J.D. I misunderstood your answer. I thought the method that you suggested redirected ALL the message to the log file OR a database table instead of in the sqlAgent history. And I was hoping to parse the log to filter out the message that I did not like.
    – QFirstLast
    Commented Feb 13, 2023 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.