Blog Post

A DMV a Day – Day 2

,

The DMV for Day 2 is sys.dm_exec_sessions, which is described by BOL as:

Returns one row per authenticated session on SQL Server. sys.dm_exec_sessions is a server-scope view that shows information about all active user connections and internal tasks. This information includes client version, client program name, client login time, login user, current session setting, and more.

This query tells you how many sessions each login has on your SQL Server instance. This query works with SQL Server 2005, 2008, and 2008 R2. It requires VIEW SERVER STATE permission.

    --  Get SQL users that are connected and how many sessions they have 
    SELECT login_name, COUNT(session_id) AS [session_count] 
    FROM sys.dm_exec_sessions 
    GROUP BY login_name
    ORDER BY COUNT(session_id) DESC;

This can be useful, especially if you use application level logins for different applications that use your database instance. If you know your baseline values for the number of connections per login, it is easier to see when something has changed.

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating