Sunday, 23 October 2016

Get the active connection of SQL-Server

With the help of below sql script we will get the active connection of the server.
SELECT Session.program_name as [Program Name],
Session.login_name as [Login Name],
Session.host_name as [Host name],
COUNT(Session.session_id) [Connections]
FROM sys.dm_exec_sessions Session
INNER JOIN sys.dm_exec_connections Conn
ON Session.session_id = Conn.session_id
WHERE Session.is_user_process = 1
GROUP BY Session.program_name,
Session.login_name,
Session.host_name
HAVING COUNT(Session.session_id) > 2
ORDER BY COUNT(Session.session_id) desc

See the example


Currently I have 4 connections

Popular Posts