Export (0) Print
Expand All
Expand Minimize

xp_logevent

SQL Server 2000

Logs a user-defined message in the Microsoft® SQL Server™ log file and in the Microsoft Windows NT® Event Viewer. xp_logevent can be used to send an alert without sending a message to the client.

Syntax

xp_logevent {error_number, 'message'} [, 'severity']

Arguments

error_number

Is a user-defined error number greater than 50,000. The maximum value is 1073741823 (230 - 1).

'message'

Is a character string with a maximum of 255 characters.

'severity'

Is one of three character strings: INFORMATIONAL, WARNING, or ERROR. severity is optional, with a default of INFORMATIONAL.

Return Code Values

0 (success) or 1 (failure)

Result Sets

xp_logevent returns this error message for the included code example:

The command(s) completed successfully.
Remarks

When sending messages from Transact-SQL procedures, triggers, batches, and so on, use the RAISERROR statement instead of xp_logevent. xp_logevent does not call a client's message handler or set @@ERROR. To write messages to the Windows NT Event Viewer and to the SQL Server error log file within SQL Server, execute the RAISERROR statement.

Permissions

Execute permissions for xp_logevent default to members of the db_owner fixed database role in the master database and members of the sysadmin fixed server role, but can be granted to other users.

Examples

This example logs the message (with variables passed to the message) in the Windows NT Event Viewer.

DECLARE @@TABNAME varchar(30)
DECLARE @@USERNAME varchar(30)
DECLARE @@MESSAGE varchar(255)
SET @@TABNAME = 'customers'
SET @@USERNAME = USER_NAME()
SELECT @@MESSAGE = 'The table ' + @@TABNAME + ' is not owned by the user 
   ' + @@USERNAME + '.'

USE master
EXEC xp_logevent 60000, @@MESSAGE, informational

See Also

PRINT

RAISERROR

System Stored Procedures (General Extended Procedures)

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft