Επεξεργασία

Κοινή χρήση μέσω


Notify an Operator of Job Status

Applies to: SQL Server Azure SQL Managed Instance

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 set notification options in SQL Server by using SQL Server Management Studio, Transact-SQL, or SQL Server Management Objects, so Microsoft SQL Server Agent can send notifications to operators about jobs.

Before You Begin

Security

For detailed information, see Implement SQL Server Agent Security.

Using SQL Server Management Studio

To notify an operator of job status

  1. In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.

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

  3. In the Job Properties dialog box, select the Notifications page.

  4. If you want to notify an operator by e-mail, check E-mail, select an operator from the list, and then select one of the following:

    • When the job succeeds to notify the operator when the job completes successfully.

    • When the job fails to notify the operator when the job completes unsuccessfully.

    • When the job completes to notify the operator regardless of completion status.

  5. If you want to notify an operator by pager, check Page, select an operator from the list, and then select one of the following:

    • When the job succeeds to notify the operator when the job completes successfully.

    • When the job fails to notify the operator when the job completes unsuccessfully.

    • When the job completes to notify the operator regardless of completion status.

  6. If you want to notify an operator by net send, check Net send, select an operator from the list, and then select one of the following:

    • When the job succeeds to notify the operator when the job completes successfully.

    • When the job fails to notify the operator when the job completes unsuccessfully.

    • When the job completes to notify the operator regardless of completion status.

Using Transact-SQL

To notify an operator of job status

  1. In Object Explorer, connect to an instance of Database Engine.

  2. On the Standard bar, click New Query.

  3. Copy and paste the following example into the query window and click Execute.

    -- adds an e-mail notification for the specified alert (Test Alert).  
    -- This example assumes that Test Alert already exists
    --  and that François Ajenstat is a valid operator name.  
    USE msdb ;  
    GO  
    EXEC dbo.sp_add_notification   
    @alert_name = N'Test Alert',   
    @operator_name = N'François Ajenstat',   
    @notification_method = 1 ;  
    GO  
    

For more information, see sp_add_notification (Transact-SQL).

Using SQL Server Management Objects

To notify an operator of job status

Use the Job class by using a programming language that you choose, such as Visual Basic, Visual C#, or PowerShell. For more information, see SQL Server Management Objects (SMO).