T-SQL script to get user session count with client IP address

Updated: Jan 11

The following SQL script helps you find user session counts for SQL Server databases based on the client IP addresses.


Might you need to report user session counts for the SQL Server database during performance troubleshooting based on the client IP address? How do you get data using the T-SQL script? Let’s find out.t you need to report user session counts for the SQL Server database during performance troubleshooting based on the client IP address? How do you get data using the T-SQL script? Let’s find out.



SELECT  d.[name] AS DBName,
      COUNT(c.connection_id) AS Connections,
       s.login_name AS LoginName,
       c.client_net_address AS IPAddress
FROM sys.dm_exec_connections c
   JOIN sys.dm_exec_sessions s on c.session_id = s.session_id
   JOIN sys.databases d on s.database_id = d.database_id
GROUP BY d.[name], s.login_name, c.client_net_address;




30 views0 comments