一、使用sp_who与sp_who2
sp_who
可以查看所有的当前连接
sp_who + 登录名
可以查看该登陆名下的所有连接
根据获取的host_name,就可以知道所在IP是多少了
ping WIN-BE48F4LV6VL -4
SELECT sqltext.TEXT, req.session_id, req.status, req.command, req.cpu_time, req.blocking_session_id, req.total_elapsed_timeFROM sys.dm_exec_requests req (NOLOCK)CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext;
SELECT * FROM sys.sysprocesses;
EXEC sp_who2;
二、sys.sysprocesses查看会话
select spid,db_name(dbid) as DBname,login_time ,last_batch ,status ,hostname ,program_name ,loginame from sys.sysprocesses where spid >50and loginame <> 'DESKTOP-ABCD\Administrator'--and dbid in (select dbid from master.dbo.sysdatabases where name ='要查询的数据库名称')order by last_batch desc
select spid,db_name(dbid) as DBname,login_time ,last_batch ,status ,hostname ,program_name ,loginame
from sys.sysprocesses
where spid >50
and loginame <> 'DESKTOP-ABCD\Administrator'
--and dbid in (select dbid from master.dbo.sysdatabases where name ='要查询的数据库名称')
order by spid
原文地址:https://blog.csdn.net/m0_37782300/article/details/105736425
三、使用Sys.dm_exec_Sessions与Sys.dm_exec_connections视图
select Session_id as spid, connect_time,client_net_address '客户端IP',local_net_address '服务器的IP' from sys.dm_exec_connections
select distinct host_name from sys.dm_exec_Sessions
根据获取的host_name,就可以知道所在IP是多少了
ping WIN-BE48F4LV6VL -4
select distinct login_name from sys.dm_exec_Sessions
网友评论