Get client IP address
Up until now, I have used convuluted approaches to get the current user client IP-address.This weekend I browsed Books Online for SQL Server 2008 R2 (November CTP) and found this new cool function!
SELECT CONNECTIONPROPERTY('net_transport') AS net_transport,
CONNECTIONPROPERTY('protocol_type') AS protocol_type,
CONNECTIONPROPERTY('auth_scheme') AS auth_scheme,
CONNECTIONPROPERTY('local_net_address') AS local_net_address,
CONNECTIONPROPERTY('local_tcp_port') AS local_tcp_port,
CONNECTIONPROPERTY('client_net_address') AS client_net_address
Or this
FROM sys.dm_exec_connections
WHERE session_id = @@SPID
引用地址 http://weblogs.sqlteam.com/peterl/archive/2010/03/20/Get-client-IP-address.aspx