Sometimes we need to check the connection for the database, using the following query we can get the total connection, login Name with Database Name.
Run below script
Run below script
SELECT DB_NAME(DBID) AS DataBaseName,
COUNT(DBID) AS TotalConnections,
loginame AS LogName
FROM sys.sysprocesses
GROUP BY DBID, loginame
ORDER BY DB_NAME(DBID)
The result will be shown below.
DataBaseName TotalConnections LogName
-------------------------------------------------
MYTESTDB 3 dkadmin
MYDKDB 119 dkadmin
MYDKDB 10 sa
master 17 sa
master 12 dkadmin
msdb 3 NT
SERVICE\SQLSERVERAGENT