Reputation: 25
I'm wondering if there is a SQL query that would show the IP of the client that wrote the query. Like if I have people making changes to my database I already have a log table but I want to add IP address to it. So I am wondering if this this possible.
Upvotes: 0
Views: 642
Reputation: 46281
If the connection was made with TCP, the query below will return the client IP address. Note that VIEW SERVER STATE
permissions are required with this method.
SELECT client_net_address
FROM sys.dm_exec_connections
WHERE
session_id = @@SPID
AND net_transport = 'TCP';
Upvotes: 1