SQL SERVER IP(Server/Client)

 

from https://stackoverflow.com/questions/142142/sql-query-to-get-servers-ip-address


//get db server machine name

SELECT SERVERPROPERTY(N'MachineName');

SELECT @@SERVERNAME;


//get db server ip

SELECT dec.local_net_address FROM sys.dm_exec_connections AS dec WHERE dec.session_id = @@SPID;



from https://www.sqlservercentral.com/forums/topic/finding-client-ip-address


//client IP

SELECT

conn.session_ID AS SPID,

conn.client_net_address AS IPAddress,

sess.HOST_NAME AS MachineName,

sess.program_name AS ApplicationName,

login_name AS LoginName

FROM sys.dm_exec_connections conn

INNER JOIN sys.dm_exec_sessions sess

ON conn.session_ID=sess.session_ID

order by IPAddress


留言

熱門文章