1

I'd like to monitor a particular SQL handle and find out who (process id) is running the SQL.

Is there a way to retrieve either a list of proc ids who executed the SQL handle in last N minutes or be automatically notified when that query is ran? or is only option is to run sys.dm_exec_requests continuously?

2
  • what does "a particular SQL handle" mean? a specific query?
    – jyao
    Commented Apr 19, 2018 at 20:21
  • @jyao - typically, in SQL Server, that would be a batch statement
    – Hannah Vernon
    Commented Apr 20, 2018 at 12:31

1 Answer 1

0

For SQL Server 2008 R2 or earlier, I'd recommend running a SQL Server Profiler session against the server.

On the General tab, in the template dropdown, select "Blank", then on the Events Selection tab, choose "SQL_StmtStarting" from the list of events. Click the "Column Filters" button, and fill it out similar to this:

enter image description here

When you run this profiler session, the results will only show you rows where the TextData column contains the text you entered. Alternately, if you have a sql handle you specifically want to track you can enter that in the filter under SqlHandle instead of TextData.

On SQL Server 2012 and above, I'd recommend using Extended Events to do this, however that is out of the scope of this question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.