List all Connections to an SQL Database

A simple, but useful command, this script will show all connections to an SQL server. Replace Database Name with the name of the database and click go.

use master
GO
select name as [database], rtrim(hostname) as hostname, rtrim(program_name) as program_name, rtrim(net_library) as net_library, rtrim(loginame) as loginame, login_time, last_batch from master.dbo.sysprocesses 
inner join master.dbo.sysdatabases on master.dbo.sysdatabases.dbid = master.dbo.sysprocesses.dbid
where name = 'Database Name' order by hostname;

Leave a Reply