sql-serverextended-events

SQL Server: Is it possible to log errors of statements or a transactions using Extended Events?


I'm logging many things via Extended Events. I saw the error_reported or errorlog_written is very generic and logs a lot of errors.

With Extended Events, is it possible to get an SQL transaction or statement error?

I'd like to get the log using Extended Events if a SQL of INSERT, SELECT, UPDATE, DELETE or other returns an error.

Is it possible?


Solution

  • I think this is a good article:

    https://dbafromthecold.com/2017/06/07/identifying-failed-queries-with-extended-events/

    I think the answer is to use error_reported with severity = 15 with says: Indicates syntax errors in the Transact-SQL command.

    https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-error-severities?view=sql-server-2017