Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
si applica a:SQL Server
Important
On Azure SQL Managed Instance, most, but not all SQL Server Agent features are currently supported. See Azure SQL Managed Instance from SQL Server for details.
Questo argomento descrive come creare un avviso di Microsoft SQL Server Agent in SQL Server che verrà generato quando si verifica un errore di un numero specifico usando SQL Server Management Studio o Transact-SQL.
Prima di iniziare
Limitazioni e restrizioni
SQL Server Management Studio offre un modo grafico semplice per gestire l'intero sistema di avvisi ed è il modo consigliato per configurare un'infrastruttura di avviso.
Gli eventi generati con xp_logevent si verificano nel database master. Pertanto, xp_logevent non attiva un avviso a meno che il @database_name per l'avviso non sia 'master' o NULL.
Sicurezza
Autorizzazioni
Per impostazione predefinita, solo i membri del sysadmin ruolo predefinito del server possono eseguire sp_add_alert.
Uso di SQL Server Management Studio
Per creare un avviso usando un numero di errore
In Object Explorer, click the plus sign to expand the server where you want to create an alert using an error number.
Click the plus sign to expand SQL Server Agent.
Fare clic con il tasto destro su Avvisi e selezionare Nuovo Avviso.
Nella finestra di dialogo Nuovo avviso, nella casella Nome, immettere un nome per questo avviso.
Check the Enable check box to enable the alert to run. Per impostazione predefinita, l'opzione Abilita è selezionata.
In the Type list, select SQL Server event alert.
Under Event alert definition, in the Database name list, select a database to restrict the alert to a specific database.
Gli avvisi in verranno generati in base a, cliccare su Numero di errore, e quindi digitare un numero di errore valido per l'avviso. Alternately, click Severity and then select the specific severity that will raise the alert.
Selezionare la casella di controllo corrispondente a Genera avviso quando il messaggio contiene per limitare l'avviso a una particolare sequenza di caratteri, quindi immettere una parola chiave o una stringa di caratteri per il testo del messaggio . Il numero massimo di caratteri è 100.
Fare clic su OK.
Using Transact-SQL
Per creare un avviso usando un numero di errore
In Object Explorer, connect to an instance of Database Engine.
On the Standard bar, click New Query.
Copiare e incollare l'esempio seguente nella finestra di query e fare clic su Esegui.
-- adds an alert (Test Alert) that runs the Back up -- the AdventureWorks2022 Database job when fired -- assumes that the message 55001 and the Back up -- the AdventureWorks2022 Database job already exist. USE msdb ; GO EXEC dbo.sp_add_alert @name = N'Test Alert', @message_id = 55001, @severity = 0, @notification_message = N'Error 55001 has occurred. The DB will be backed up...', @job_name = N'Back up the AdventureWorks2022 Database' ; GO
Per altre informazioni, vedere sp_add_alert (Transact-SQL).