:::: MENU ::::

Get list of all current connections to SQL Server instance

  • Mar 25 / 2009
  • 0
dbDigger, Monitoring and Analysis, T-SQL Scripts

Get list of all current connections to SQL Server instance

List of all current connections to SQL Server instance can be found in SSMS or Enterprise Manager. But these tools are not always accessible and also expert DBAs like to generate lists by code as it is flexible and easy to analyze. So to get list of all current connections to SQL Server instance use following script.

 
SELECT DB_NAME(dbid)AS ConnectedToDB,  
 hostname, program_name,loginame,  
 cpu, physical_io, memusage, login_time,  
 last_batch, [status]  
 FROM master.dbo.sysprocesses  
 ORDER BY dbid, login_time, last_batch  
 GO  

Also you can filter the results for a single user or a single database by providing filter criteria in where clause as required. For example to get just connections to database you may add following condition in where clause

 
WHERE dbid = DB_ID ('AdventureWorks')  

Similarly you may filter the results with relevance to any column as required. Above script can be used on all versions of SQL Server.

Consult us to explore the Databases. Contact us