Query Connection Data – SQL Server

use [master]
go
SELECT 
    DB_NAME(dbid) as DBName, 
    COUNT(dbid) as NumberOfConnections,
    loginame as LoginName
FROM
    sys.sysprocesses
WHERE 
    dbid > 0
GROUP BY 
    dbid, loginame
order by 2 desc

SELECT *
 FROM sys.dm_exec_sessions
 where host_name is not null
 order by login_name
 go