Skip to content

Instantly share code, notes, and snippets.

@Cyberloki
Created September 22, 2013 21:43
Show Gist options
  • Save Cyberloki/6664157 to your computer and use it in GitHub Desktop.
Save Cyberloki/6664157 to your computer and use it in GitHub Desktop.
Query SP_Who2 Who is accessing particular database programname and login
DECLARE @coffee TABLE (
spid int
, [status] varchar(50)
, [Login] varchar(255)
, HostName varchar(255)
, BlkBy varchar(50)
, [DBName] varchar(255)
, [Command] varchar(255)
, CPUTime int
, DiskIO int
, LastBatch varchar(255) -- DateTime
, ProgramName varchar(255)
, SPID_ int
, request_id int
)
INSERT INTO @coffee EXEC sp_who2
SELECT * FROM @coffee where [dbname] = 'MyDB' and [ProgramName] = 'MyApp' order by [login]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment