How to check open connection in sql server

We can check open connection of our database using inbuilt stored procedure.

You can use sp_who stored procedure. It provides information about current users, sessions, and processes in database instance.

You can also use undocumented stored procedures sp_who2 which gives you more detailed information

You can also use below query for it

SELECT
DB_NAME(dbid) as DBName,
COUNT(dbid) as NoOfConnections,
loginame as LoginName
FROM
sys.sysprocesses
WHERE
dbid > 0
GROUP BY
dbid, loginame