I am trying to create a trace for user error messages using audit user error messages event class.I could create .trc file. But , unfortunately I am unable to get sql query which caused the error . I cannot use profiler to create and see the trace files as it is against our requirement.
This is how I created the trace file
1) DECLARE @.TraceIdOut int
Exec sp_trace_create @.traceid= @.TraceIdOut OUTPUT
,@.options = 2 ,@.tracefile =N'c:\Parseerrors'
PRINT @.TraceIdOut
2) Set the trace event to monitor Parse error messages
Exec sp_trace_setevent @.traceid = 2,@.eventid = 162,@.columnid =1, @.on = @.On
3) Set the trace event status to start.
EXEC sp_trace_setstatus @.traceid = 2, @.status = 1
I am getting only one column ..that is column which shows the user error..
for example "incorrect syntax near 'abcd' ".
I also want the sql query which caused the error. I could give only one columnid number while setting the trace event.
Please help me in getting the sql query which caused this error.
Each execution of 'sp_trace_setevent' will set a single column capture for the given event. If you want to capture different columns for the same event, include multiple back-to-back executions of 'sp_trace_setevent' with the same @.traceid and @.eventid values, but different @.columnid values.
Might find it easier if you opened profiler and configured the trace graphically with the events and columns you'd like to capture then start it and stop it immediately, then choose to script it from the 'File...Export...Script Trace Definition' menu option(s)...that will create a script file with the commands you would want to use to capture via a server-side trace.
HTH
No comments:
Post a Comment