Note: This blog post is from 2015. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
Often when people are trying to troubleshoot seeming problems in ColdFusion (or whatever app server you may use), they may wonder if (or have tools which suggest that) their CF requests are being held up waiting for a query to run in the database, which seems hung up.
Wouldn't it be nice to know, at any moment (such as when things are going badly), just what queries (or stored procedures or commands) were running in the database at that point in time?
Well here's good news: if you're running SQL Server, the following SQL query will show you just that: the currently running SQL statement(s) and some additional details about each query including their duration, their database name, the program executing the SQL, the session id, and much more.
For more (including why things like Activity Monitor, sp_who2, and others aren't the answer, as well as what to do if you may be unable to run this code), please read on.