Click here to Skip to main content
11,410,365 members (54,205 online)
Click here to Skip to main content

Tagged as

Get Client IP Address in SQL Server

, 23 Feb 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
How to get the client IP address in SQL Server


Execute the below function and call this function through a Stored Procedure. It will return the IP address of the client system.

CREATE FUNCTION [dbo].[GetCurrentIP] ()
RETURNS varchar(255)
    DECLARE @IP_Address varchar(255);
    SELECT @IP_Address = client_net_address
    FROM sys.dm_exec_connections
    WHERE Session_id = @@SPID;
    Return @IP_Address;

or we can get the same result by using the below query:

SELECT CONVERT(char(15), CONNECTIONPROPERTY('client_net_address'))



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sarvesh Kumar Gupta
Software Developer (Senior) Edge Business Solution
India India
Working in Edge Business Solution as a Senior Software Developer. I have more than 7 years exp. in Microsoft Technologies. I have exp. in ASP.Net, C#, SQL 2000/2005/2008 R2, Javascript, Ajax, JQuery, MVC, LINQ etc.
Follow on   Twitter   LinkedIn

Comments and Discussions

Suggestionshort way PinmemberMember 148265318-Jun-14 4:08 
GeneralRe: short way PinmemberSarvesh Kumar Gupta24-Jun-14 22:15 
GeneralReason for my vote of 5 simple Pinmembermember601-Mar-12 1:21 
Generalsimple Pinmembermember601-Mar-12 1:20 
GeneralGood one. But when i login to my SSMS with Server as '.'. it... PinmemberBhuvanRamIconcept27-Feb-12 19:15 
GeneralReason for my vote of 5 gratz... PinmemberPolinia27-Feb-12 6:39 
GeneralReason for my vote of 5 good one Pinmembernikhi _singh24-Feb-12 19:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150414.5 | Last Updated 23 Feb 2012
Article Copyright 2012 by Sarvesh Kumar Gupta
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid