T-SQL Query to find IP Address of SQL Server | SansSQL

Saturday, March 23, 2013

T-SQL Query to find IP Address of SQL Server

Here is a handy T-SQL script to find the IP Address of the SQL Server you are connected to.

SELECT CONNECTIONPROPERTY('local_net_address') AS [IP Address Of SQL Server]

SELECT SERVERPROPERTY('ComputerNamePhysicalNetBIOS') [Machine Name]
   ,SERVERPROPERTY('InstanceName') AS [Instance Name]
   ,LOCAL_NET_ADDRESS AS [IP Address Of SQL Server]
   ,CLIENT_NET_ADDRESS AS [IP Address Of Client]
 FROM SYS.DM_EXEC_CONNECTIONS 
 WHERE SESSION_ID = @@SPID

3 comments:

karthik babu said...

Thnx a lot.. god bless...

thongchai.jindatam said...

SELECT CLIENT_NET_ADDRESS AS [IP Address Of Client]
FROM SYS.DM_EXEC_CONNECTIONS
WHERE SESSION_ID = @@SPID


RESULT >>> local machine

Help Me plese

Sandesh Segu said...

You have to run this query from a remote PC to get IP address. If you are running from the same server as SQL server then the query returns Local Machine.

Post a Comment