How do I see active SQL Server connections?

后端 未结 8 848
暖寄归人
暖寄归人 2020-11-28 00:13

I am using SQL Server 2008 Enterprise. I want to see any active SQL Server connections, and the related information of all the connections, like from which IP address, conne

相关标签:
8条回答
  • 2020-11-28 01:04

    Click the "activity monitor" icon in the toolbar.

    From Thorsten's comment:

    In SQL Server Management Studio, right click on Server, choose "Activity Monitor" from context menu -or- use keyboard shortcut Ctrl + Alt + A.

    Reference: Microsoft Docs - Open Activity Monitor in SQL Server Management Studio (SSMS)

    0 讨论(0)
  • 2020-11-28 01:05

    Below is my script to find all the sessions connected to a database and you can check if those sessions are doing any I/O and there is an option to kill them.

    The script shows also the status of each session.

    Have a look below.

    --==============================================================================
    -- See who is connected to the database.
    -- Analyse what each spid is doing, reads and writes.
    -- If safe you can copy and paste the killcommand - last column.
    -- Marcelo Miorelli
    -- 18-july-2017 - London (UK)
    -- Tested on SQL Server 2016.
    --==============================================================================
    USE master
    go
    SELECT
         sdes.session_id
        ,sdes.login_time
        ,sdes.last_request_start_time
        ,sdes.last_request_end_time
        ,sdes.is_user_process
        ,sdes.host_name
        ,sdes.program_name
        ,sdes.login_name
        ,sdes.status
    
        ,sdec.num_reads
        ,sdec.num_writes
        ,sdec.last_read
        ,sdec.last_write
        ,sdes.reads
        ,sdes.logical_reads
        ,sdes.writes
    
        ,sdest.DatabaseName
        ,sdest.ObjName
        ,sdes.client_interface_name
        ,sdes.nt_domain
        ,sdes.nt_user_name
        ,sdec.client_net_address
        ,sdec.local_net_address
        ,sdest.Query
        ,KillCommand  = 'Kill '+ CAST(sdes.session_id  AS VARCHAR)
    FROM sys.dm_exec_sessions AS sdes
    
    INNER JOIN sys.dm_exec_connections AS sdec
            ON sdec.session_id = sdes.session_id
    
    CROSS APPLY (
    
        SELECT DB_NAME(dbid) AS DatabaseName
            ,OBJECT_NAME(objectid) AS ObjName
            ,COALESCE((
                SELECT TEXT AS [processing-instruction(definition)]
                FROM sys.dm_exec_sql_text(sdec.most_recent_sql_handle)
                FOR XML PATH('')
                    ,TYPE
                ), '') AS Query
    
        FROM sys.dm_exec_sql_text(sdec.most_recent_sql_handle)
    
    ) sdest
    WHERE sdes.session_id <> @@SPID
      AND sdest.DatabaseName ='yourdatabasename'
    --ORDER BY sdes.last_request_start_time DESC
    
    --==============================================================================
    
    0 讨论(0)
提交回复
热议问题