Adds a new trace queue and sets trace queue configuration values, including the size of the trace queue (the number of items to be held in the trace queue at one time).
Important When using the shared memory network library, Microsoft® SQL Server™ does not support impersonation unless connected by using Windows NT Authentication. To execute a SQL Server Profiler Extended Procedure against a local server through SQL Server Query Analyzer, use Windows NT Authentication.
xp_trace_addnewqueue {max_items, timeout, thread_boost, thread_reduce,
required_columns, queue_handle OUTPUT}
Value | Description |
---|---|
1 | Text data |
2 | Binary data |
4 | Database ID |
8 | Transaction ID |
16 | Connection ID |
32 | Microsoft Windows NT® username |
64 | Windows NT domain name |
128 | Host name |
256 | Host process ID |
512 | Application name |
1024 | SQL username |
2048 | SQL process ID (SPID) |
4096 | Duration |
8192 | Start time |
16384 | End time |
32768 | Reads |
65536 | Writes |
131072 | CPU usage |
524288 | Severity |
1048576 | Event Subclass |
2097152 | Object ID |
8388608 | Index ID |
16777216 | Integer data |
33554432 | Server name |
67108864 | Event Class |
0 (success) or >1 (failure)
xp_trace_addnewqueue returns this message:
The command(s) completed successfully.
After a trace queue is created, there may come a time when the trace queue must be either stopped, or destroyed. For more information about stopping or destroying a trace queue, see Deleting Traces.
There are some special considerations when using the Replay feature of SQL Server Profiler which pertain to passwords, permissions, and authentication. For more information, see Replaying Traces.
Execute permissions for xp_trace_addnewqueue default to members of the sysadmin fixed server role but can be granted to other users.
This example creates a trace queue that writes events to a file and autostarts whenever the server is restarted.
--Declare the variables.
DECLARE @queue_handle int --queue handle to refer
--to this trace by
DECLARE @column_value int --data column bitmask
--Set the column mask for the data columns to capture
SET @column_value = 1|16|3|8192|128|512
--Create a queue.
EXEC xp_trace_addnewqueue 1000,
5,
95,
90,
@column_value,
@queue_handle OUTPUT
--Specify the event classes to trace.
--To look up the names, execute xp_trace_geteventnames.
EXEC xp_trace_seteventclassrequired @queue_handle,
10, 1 --RPC:Completed
EXEC xp_trace_seteventclassrequired @queue_handle,
12, 1 --SQL:BatchCompleted
EXEC xp_trace_seteventclassrequired @queue_handle,
14, 1 --Connect
EXEC xp_trace_seteventclassrequired @queue_handle,
16, 1 --Disconnect
EXEC xp_trace_seteventclassrequired @queue_handle,
17, 1 --ExistingConnection
--Set any filters. (Don't trace the Profiler).
EXEC xp_trace_setappfilter @queue_handle,
NULL,
'SQL Server Profiler%'
--Configure the queue to write to a file.
EXEC xp_trace_setqueuedestination @queue_handle,
2,
1,
NULL,
'c:\temp\demo.trc'
--Start the consumer that actually writes to a file.
EXEC xp_trace_startconsumer @queue_handle
--Display the queue handle. It will be needed
--later to stop the queue.
SELECT @queue_handle
--Save the queue definition as DemoQueue.
EXEC xp_trace_savequeuedefinition @queue_handle,
'DemoQueue',
1
--Mark it for autostart
EXEC xp_trace_setqueueautostart 'DemoQueue', 1