Tuesday, July 22, 2014

How to get SQL Server IP Address in SQL Query?

Get IP Address of SQL Server using SQL Query:

I have a situation to get the SQL Server IP Address. My SQL Server was in different IP Address and my web application was in different address. Some time we need to get both SQL Client and SQL Server Local IP Address. The below Example will help me to get the both client and sql server IP’s.
@@SPID – This is the session ID of particular connection. Each connection have different session ID.

SELECT   client_net_address,local_net_address, @@SPID as SPID
FROM sys.dm_exec_connections
WHERE Session_id = @@SPID;

I hope the above SQL Query will help you to get the SQL Server IP Address.

If you want to learn more ablut @@SPID Please check the below link