Skip to content

Latest commit

 

History

History
72 lines (48 loc) · 3.75 KB

write-the-job-status-to-the-windows-application-log.md

File metadata and controls

72 lines (48 loc) · 3.75 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic helpviewer_keywords monikerRange
Write the Job Status to the Windows Application Log
Write the Job Status to the Windows Application Log
markingmyname
maghan
01/19/2017
sql
ssms
how-to
status information [SQL Server], jobs
SQL Server Agent jobs, status
writing job status to log
jobs [SQL Server Agent], status
logs [SQL Server], jobs
= azuresqldb-mi-current || >= sql-server-2016

Write the Job Status to the Windows Application Log

[!INCLUDE SQL Server SQL MI]

Important

On Azure SQL Managed Instance, most, but not all SQL Server Agent features are currently supported. See Azure SQL Managed Instance T-SQL differences from SQL Server for details.

This topic describes how to configure [!INCLUDEmsCoName] [!INCLUDEssNoVersion] Agent in [!INCLUDEssnoversion] to write job status to the Windows application event log by using SQL Server Management Studio, [!INCLUDEtsql], or SQL Server Management Objects.

Job responses ensure that database administrators know when jobs complete and how frequently they run. Typical job responses include:

  • Notifying the operator by using e-mail, electronic paging, or a net send message. Use one of these job responses if the operator must perform a follow-up action. For example, if a backup job completes successfully, the operator must be notified to remove the backup tape and store it in a safe location.

  • Writing an event message to the Windows application log. You can use this response only for failed jobs.

  • Automatically deleting the job. Use this job response if you are certain that you do not need to rerun this job.

Before You Begin

Security

For detailed information, see Implement SQL Server Agent Security.

Using SQL Server Management Studio

To write job status to the Windows application log

  1. In Object Explorer, connect to an instance of the [!INCLUDEssDEnoversion], and then expand that instance.

  2. Expand SQL Server Agent, expand Jobs, right-click the job you want to edit, and then click Properties.

  3. Select the Notifications page.

  4. Check Write to Windows application event log, and choose one of the following:

    • Click When the job succeeds to log the job status when the job completes successfully.

    • Click When the job fails to log the job status when the job completes unsuccessfully.

    • Click When the job completes to log the job status regardless of completion status.

Using SQL Server Management Objects

To write job status to the Windows application log

Call the EventLogLevel property of the Job class by using a programming language that you choose, such as Visual Basic, Visual C#, or PowerShell.

The following code example sets the job to generate an operating system event log entry when the job execution finishes.

PowerShell

$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$jb = new-object Microsoft.SqlServer.Management.Smo.Agent.Job($srv.JobServer, "Test Job")  
$jb.EventLogLevel = [Microsoft.SqlServer.Management.Smo.Agent.CompletionAction]::Always