Monday, March 5, 2012

Examining SQL Server sessions

I recently needed to see the number of SQL Server sessions connected to a database, and what they were doing.

There are these handy stored procedures to list the current (and currently executing) sessions in a SQL Server database.

sp_who: Comes pre-installed. Lists session currently connected to a database. More info here.



But typically people prefer sp_who2, which displays more information.

sp_who2: Comes pre-installed. Lists session currently connected to a database. More info here.


But to easily see the active sessions, and what they're currently doing, you want sp_who3.

sp_who3: You need to install this yourself.  (Definition is here.) Lists only sessions with a currently executing request, along with what that SQL statement is.