SQL Server代理在作业历史中记录自定义消息

时间:2022-12-22 09:22:06

Is it possible to log custom messages from your SQL Server Agent job in the job history messages? If not what's the best way to go about doing such a thing?

是否可以将SQL Server代理任务中的自定义消息记录到作业历史消息中?如果不是,做这样的事最好的方法是什么?

2 个解决方案

#1


4  

For T-SQL job steps, you can use the print statement. For CmdExec steps, use Console.Writeline in your executable. If there is a lot of output, then by default SQL Agent will not keep all of, and will only keep a certain number of characters. To have it keep all output for a step, you go to the step properties, Advanced, and check the "Include step output in history" checkbox.

对于T-SQL作业步骤,可以使用print语句。对于CmdExec步骤,请使用控制台。Writeline在你的可执行文件。如果有大量的输出,那么默认情况下SQL代理将不会保留所有的,并且只保留一定数量的字符。要让它保留一个步骤的所有输出,您可以转到step属性Advanced,并选中“包含历史中的步骤输出”复选框。

#2


1  

I haven't done it for a while, but I believe text generated by a PRINT statements in the code executed by the job will end up in the history table. If that doesn't work, RAISERROR with severity less than 11 should do it. (11 and up definitely will, but then jobs are marked as having failed.)

我已经有一段时间没有这样做了,但是我相信由工作执行的代码中打印语句生成的文本将会出现在历史表中。如果这不起作用,那么严重性小于11的RAISERROR也应该这样做。(11岁以上的人肯定会这么做,但接下来的工作被打上了失败的标签。)

#1


4  

For T-SQL job steps, you can use the print statement. For CmdExec steps, use Console.Writeline in your executable. If there is a lot of output, then by default SQL Agent will not keep all of, and will only keep a certain number of characters. To have it keep all output for a step, you go to the step properties, Advanced, and check the "Include step output in history" checkbox.

对于T-SQL作业步骤,可以使用print语句。对于CmdExec步骤,请使用控制台。Writeline在你的可执行文件。如果有大量的输出,那么默认情况下SQL代理将不会保留所有的,并且只保留一定数量的字符。要让它保留一个步骤的所有输出,您可以转到step属性Advanced,并选中“包含历史中的步骤输出”复选框。

#2


1  

I haven't done it for a while, but I believe text generated by a PRINT statements in the code executed by the job will end up in the history table. If that doesn't work, RAISERROR with severity less than 11 should do it. (11 and up definitely will, but then jobs are marked as having failed.)

我已经有一段时间没有这样做了,但是我相信由工作执行的代码中打印语句生成的文本将会出现在历史表中。如果这不起作用,那么严重性小于11的RAISERROR也应该这样做。(11岁以上的人肯定会这么做,但接下来的工作被打上了失败的标签。)