Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

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

Introduction

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)
AS
BEGIN
    DECLARE @IP_Address varchar(255);
 
    SELECT @IP_Address = client_net_address
    FROM sys.dm_exec_connections
    WHERE Session_id = @@SPID;
 
    Return @IP_Address;
END

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

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

Enjoy.

License

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

Share

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 3:08 
GeneralRe: short way PinmemberSarvesh Kumar Gupta24-Jun-14 21:15 
GeneralReason for my vote of 5 simple Pinmembermember601-Mar-12 0:21 
Generalsimple Pinmembermember601-Mar-12 0:20 
GeneralGood one. But when i login to my SSMS with Server as '.'. it... PinmemberBhuvanRamIconcept27-Feb-12 18:15 
GeneralReason for my vote of 5 gratz... PinmemberPolinia27-Feb-12 5:39 
GeneralReason for my vote of 5 good one Pinmembernikhi _singh24-Feb-12 18:29 
Reason for my vote of 5
good one

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 | Mobile
Web04 | 2.8.140916.1 | Last Updated 23 Feb 2012
Article Copyright 2012 by Sarvesh Kumar Gupta
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid