获取SQL Server中连接的客户端IP地址[转]
有时候需要获取连接到SQL Server服务器上的客户端IP地址,用什么办法呢?
SELECT *FROM sys.dm_exec_connections
WHERE session_id = @@SPID
这个办法不知道在SQL2005和以前版本是否可以
如果是SQL Server2008,还可以用CONNECTIONPROPERTY方法获取:
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