Home Blog SQL MSSQL sp_who2 check on number of connections
MSSQL sp_who2 check on number of connections
SQL
Written by Dicky   
Monday, 26 September 2016 09:38
AddThis Social Bookmark Button

In order to check the number of connections currently running on your DB or debug an issue where application not closing SQL connections properly, simply execute the following command.

 

DECLARE @Table TABLE(
 SPID INT,
 Status VARCHAR(MAX),
 LOGIN VARCHAR(MAX),
 HostName VARCHAR(MAX),
 BlkBy VARCHAR(MAX),
 DBName VARCHAR(MAX),
 Command VARCHAR(MAX),
 CPUTime INT,
 DiskIO INT,
 LastBatch VARCHAR(MAX),
 ProgramName VARCHAR(MAX),
 SPID_1 INT,
 REQUESTID INT
)

INSERT INTO @Table EXEC sp_who2

SELECT  DBName, Status, COUNT(*)
FROM    @Table
WHERE DBName IN ('DBNAME')
GROUP BY DBName, Status

The query was taken from this article.