The following code returns some rows with [Error] = 2

 v1.[name] as EventName, tr.TextData, tr.HostName, tr.ApplicationName, tr.LoginName, tr.SPID, tr.Duration, 
 tr.StartTime, tr.EndTime, tr.Reads, tr.Writes, tr.CPU, tr.ServerName, tr.Error, tr.ObjectName, tr.RowCounts
 sys.trace_events as v1
 INNER JOIN fn_trace_gettable(@v_path, DEFAULT) as tr ON tr.EventClass = v1.trace_event_id 
 tr.TextData IS NOT NULL AND
 (tr.EndTime > @v_maxEndTime OR @v_maxEndTime IS NULL)

Where can I see the list of error codes for fn_trace_gettable to understand what this one means?

  • Where do you execute this code? What is your full server version (the result of select @@version)? – sepupic Nov 13 '19 at 8:42
  • Microsoft SQL Server 2017 (RTM-CU15) (KB4498951) - 14.0.3162.1 (X64) May 15 2019 19:14:30 Copyright (C) 2017 Microsoft Corporation Standard Edition (64-bit) on Windows Server 2016 Datacenter 10.0 <X64> (Build 14393: ) (Hypervisor) – Yevgeni Grinberg Nov 13 '19 at 15:07

The most common error codes when tracing regular query execution will be 0, 1 or 2.

0 = OK, 1 = Error, 2 = Abort


In your case, error code 2 = abort, meaning that a query was cancelled due to such things as a timeout or a user action.

You can test this by starting a trace, running a query and stopping it before execution end:

enter image description here

The official definition shows that other error messages might be shown dependent on which events you select:

enter image description here

The same is true for the docs on traces.

enter image description here

These errors and their definition can be found in:

FROM sys.sysmessages;

Testing this could be done by selecting error events:

enter image description here

Running a divide by zero query to produce an error:

enter image description here

Finding the exception error number:

enter image description here

And then querying sys.sysmessages:

FROM sys.sysmessages
where error = 8134;


enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.