Поделиться через


Create a WMI event alert

применимо к:SQL ServerУправляемому экземпляру SQL Azure

Это важно

В Azure SQL Managed Instanceв настоящее время поддерживается большинство функций агента SQL Server, но не все. Дополнительные сведения см. в статье «Различия T-SQL в управляемом экземпляре SQL Azure по сравнению с SQL Server».

This article describes how to a SQL Server Agent alert that is raised when a specific SQL Server event occurs that is monitored by the WMI Provider for Server Events in SQL Server by using SQL Server Management Studio or Transact-SQL.

For information about the using the WMI Provider to monitor SQL Server events, see WMI Provider for Server Events Classes and Properties. For information about the permissions necessary to receive WMI event alert notifications, see Select an Account for the SQL Server Agent Service. For more information about WQL, see Using WQL with the WMI Provider for Server Events.

Ограничения и запреты

  • SQL Server Management Studio предоставляет простой графический способ управления всей системой оповещений и рекомендуется настроить инфраструктуру оповещений.

  • Events generated with xp_logevent occur in the master database. Therefore, xp_logevent does not trigger an alert unless the @database_name for the alert is 'master' or NULL.

  • Only WMI namespaces on the computer that runs SQL Server Agent are supported.

Разрешения

By default, only members of the sysadmin fixed server role can execute sp_add_alert.

Используйте SQL Server Management Studio

  1. In Object Explorer, select the plus sign to expand the server where you want to create a WMI event alert.

  2. Select the plus sign to expand SQL Server Agent.

  3. Right-click Alerts and select New Alert.

  4. В диалоговом окне Новое оповещение в поле "Имя" введите имя этого оповещения.

  5. Установите флажок Включить, чтобы включить запуск оповещения. По умолчанию флажок Включить отмечен.

  6. In the Type list, select WMI event alert.

  7. Under WMI event alert definition, in the Namespace box, specify the WMI namespace for the WMI Query Language (WQL) statement that identifies which WMI event will trigger this alert.

  8. In the Query box, specify the WQL statement that identifies the event that this alert responds to.

  9. Нажмите ОК.

Использование Transact-SQL

  1. В обозревателе объектов подключитесь к экземпляру ядра СУБД.

  2. На стандартной панели выберите пункт Создать запрос.

  3. Скопируйте приведенный ниже пример в окно запроса и нажмите кнопку Выполнить.

    USE msdb;
    GO
    
    EXEC dbo.sp_add_alert @name = N'Test Alert 2',
        @message_id = 54001,
        @notification_message = N'Error 54001 has occurred on the Sales.SalesOrderDetail table on the AdventureWorks2022 database.',
        @wmi_namespace = '\.\root\Microsoft\SqlServer\ServerEvents',
        @wmi_query = N'SELECT * FROM ALTER_TABLE
    WHERE DatabaseName = ''AdventureWorks2022'' AND SchemaName = ''Sales''
    AND ObjectType=''Table'' AND ObjectName = ''SalesOrderDetail''';
    GO
    

Дальнейшие действия