view:
CREATE VIEW [dbo].[vw_ActiveCxns] AS
SELECT db_name(dbid) as DatabaseName, hostname HostName, d.client_net_address IPaddress, loginame as LoginName, count(dbid) as NoOfConnections
FROM sys.sysprocesses s JOIN sys.dm_exec_connections d ON s.spid = d.session_id
WHERE dbid > 4
AND Loginame NOT IN (.............)
GROUP BY dbid, hostname,loginame,d.client_net_address
GO
proc:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[usp_OpenCxns] (
@login varchar(50)=NULL
)
AS
SET NOCOUNT ON;
/* Simply returns all active connections, per database.
EXEC dbo.usp_OpenCxns @login = 'xxxx' */
BEGIN TRAN
BEGIN TRY
/* SELECT db_name(dbid) as DatabaseName, hostname HostName, d.client_net_address IPaddress, loginame as LoginName, count(dbid) as NoOfConnections
FROM sys.sysprocesses s JOIN sys.dm_exec_connections d ON s.spid = d.session_id
WHERE dbid > 4
AND (@login IS NULL OR s.loginame = @login)
GROUP BY ROLLUP(dbid, hostname,loginame,d.client_net_address)
ORDER BY DatabaseName,LoginName,d.client_net_address,NoOfConnections */
SELECT DatabaseName,HostName,IPAddress,LoginName,NoOfConnections
FROM dbo.vw_ActiveCxns
WHERE (@login IS NULL OR LoginName = @login)
END TRY
BEGIN CATCH
ROLLBACK
END CATCH
IF @@TRANCOUNT >0
COMMIT TRAN
SET NOCOUNT OFF;
GO
|