Skip to content

Instantly share code, notes, and snippets.

@regisbsb
Created November 26, 2015 10:44
Show Gist options
  • Save regisbsb/ed428a3421b4dad87841 to your computer and use it in GitHub Desktop.
Save regisbsb/ed428a3421b4dad87841 to your computer and use it in GitHub Desktop.
Shows the last command on connection
SELECT S.spid, login_time, last_batch, status, hostname, program_name, cmd,
(
select text from sys.dm_exec_sql_text(S.sql_handle)
) as last_sql
FROM sys.sysprocesses S
where dbid > 0
and DB_NAME(dbid) = '<my_database_name>'
and loginame = '<my_application_login>'
order by last_batch asc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment