HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

What is the request_id in sys.dm_exec_requests and how does it change?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
request_idthewhatsysdm_exec_requestsdoeshowandchange

Problem

According to MSDN, the request_id in sys.dm_exec_requests is the


"ID of the request. Unique in the context of the session. Is not
nullable."

It always appears to be 0, from casual observation.

Can someone tell me how, for a given session, this id can ever be more than 0? Is it possible to reproduce this with some sql?

Thanks!

Solution

Can someone tell me how, for a given session, this id can ever be more
than 0? Is it possible to reproduce this with some sql?

The request_id other than zero indicates a connection with Multiple Active Result Sets (MARS) enabled. With MARS, a single connection may have multiple active statements, with statement execution interleaved.

From SSMS, open a new query window connection specifying MultipleActiveResultSets=Trueunder "Options-->Additional Connection Parameters". Then run the query below in the window. You should see a non-zero request_id value.

SELECT * 
FROM sys.dm_exec_requests
WHERE session_id = @@SPID;

Code Snippets

SELECT * 
FROM sys.dm_exec_requests
WHERE session_id = @@SPID;

Context

StackExchange Database Administrators Q#131695, answer score: 5

Revisions (0)

No revisions yet.