SQL Script to check database connections and their status

The following T-SQL script returns the existing database connections, their status, originating host name and IP address. You can use this script for on-premise SQL Server, Azure SQL Database and Azure SQL Managed Instances.


SELECT
    dmc.session_id, des.status,
     des.host_name, des.program_name,
 des.login_name, des.nt_domain,
    des.nt_user_name, des.original_login_name, dmc.connect_time,
    des.login_time
FROM sys.dm_exec_connections AS dmc
JOIN sys.dm_exec_sessions AS des
    ON dmc.session_id = des.session_id
--WHERE c.session_id = @@SPID;
ORDER BY dmc.connect_time ASC

SQL Script to check database connections and their status - Azure SQL Database

29 views0 comments