How to get detailed list of connections to database in sql server 2005?

前端 未结 4 1828
遥遥无期
遥遥无期 2021-02-18 18:24

How to get detailed list of connections to database in sql server 2005?

4条回答
  •  孤独总比滥情好
    2021-02-18 18:59

    sp_who2 will actually provide a list of connections for the database server, not a database. To view connections for a single database (YourDatabaseName in this example), you can use

    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 = 'YourDatabaseName'
    

    (Adapted from SQL Server: Filter output of sp_who2.)

提交回复
热议问题