Permission error when using sys.dm_exec_input_buffer with @@SPID
Using the condition WHERE req.session_id = &lt;some value&gt; triggers the error condition. Then the line is ignored, and the rest runs correctly. Try executing:

SELECT      event_info
FROM        sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_input_buffer(req.session_id, req.request_id)


without the WHERE clause, and you should get the correct output.

tl;dr Looking for a specific session_id triggers the error.