Click here to Skip to main content
13,343,008 members (54,478 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


12 bookmarked
Posted 21 Feb 2012

Get Client IP Address in SQL Server

, 23 Feb 2012
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.

You may also be interested in...


Comments and Discussions

QuestionSQL 2014? Pin
harveyt21-May-15 10:35
memberharveyt21-May-15 10:35 
Suggestionshort way Pin
Member 148265318-Jun-14 4:08
memberMember 148265318-Jun-14 4:08 
GeneralRe: short way Pin
Sarvesh Kumar Gupta24-Jun-14 22:15
memberSarvesh Kumar Gupta24-Jun-14 22:15 
GeneralReason for my vote of 5 simple Pin
member601-Mar-12 1:21
membermember601-Mar-12 1:21 
Reason for my vote of 5
Generalsimple Pin
member601-Mar-12 1:20
membermember601-Mar-12 1:20 
GeneralGood one. But when i login to my SSMS with Server as '.'. it... Pin
BhuvanRamIconcept27-Feb-12 19:15
memberBhuvanRamIconcept27-Feb-12 19:15 
GeneralReason for my vote of 5 gratz... Pin
Polinia27-Feb-12 6:39
memberPolinia27-Feb-12 6:39 
GeneralReason for my vote of 5 good one Pin
nikhi _singh24-Feb-12 19:29
membernikhi _singh24-Feb-12 19:29 

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

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

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