DECLARE @DB_NAME varchar(1000) SELECT @DB_NAME = 'Northwind_DB' DECLARE @AllConnections TABLE( SPID INT, Status VARCHAR(MAX), LOGIN VARCHAR(MAX), HostName VARCHAR(MAX), BlkBy VARCHAR(MAX), DBName VARCHAR(MAX), Command VARCHAR(MAX), CPUTime INT, DiskIO INT, LastBatch VARCHAR(MAX), ProgramName VARCHAR(MAX), SPID_1 INT, REQUESTID INT ) INSERT INTO @AllConnections EXEC sp_who2 SELECT * FROM @AllConnections WHERE DBName = @DB_Name ORDER BY HostName
Tuesday, July 31, 2018
Get "exec sp_who2" into a table
Running sp_who2 will quickly display all connections to a SQL Server instance. Below is an enhancement to sp_who2 that allows database-specific connections.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment