A personal repository of technical notes. - CSC

How to Write Output to SQL Server Job History Log

Problem

Need to generate custom output in job history of an operating system job type.

Solution

1) Check this box in SQL Server Management Studio: Job Step Properties / Advanced / Include step output in history

2) Generate output in job's executable. C#.NET example:

private static void TestSqlJobOutput()
{
       System.Console.WriteLine("Sample Error Message 1"); // Shows up in SQL Server job history log.
       Environment.ExitCode = 1; // Causes SQL Server job step to fail when application ends.
}

No comments:

Post a Comment