Monitoring Active SQL Server Sessions

The sys.dm_exec_sessions view returns information about all active sessions connected to SQL Server. A session represents a single connection between the SQL Server and a client application.


Key Columns:

  • session_id: The unique identifier for the session.
  • login_name: The name of the user who initiated the session.
  • status: The status of the session (e.g., running, sleeping).
  • host_name: The name of the client machine connected to the SQL Server.
  • program_name: The name of the client program (e.g., SQL Server Management Studio).
  • login_time: The time the user logged in.


Use Case:

You can use sys.dm_exec_sessions to monitor all active connections and sessions on the server, including idle sessions that are not actively running queries.


Example Query:

SELECT session_id, login_name, status, host_name, program_name, login_time
FROM sys.dm_exec_sessions;