Remote Client IP address Accc In SQL Server
-
Thursday, December 17, 2009 6:04 PMWhat I want to know when my client application written in the Java connect SQL server then SQL server can provide me the Local IP address of the client machine.
Do we have any mechanism in the SQL server to know the Client machine IP address?
Any help will be greatful.
shawn aslam
All Replies
-
Friday, December 18, 2009 2:07 AM
1. You can get that from SQL server profiler trace files. open the trc files with SQL profiler where you can see the hostname , login name etc from here.
2. You can also look in to the sys.dm_exec_sessions the field hostname will give the computer name (or eventually the ip address).
Thanks, Leks- Marked As Answer by Stoyko Kostov - MSFTModerator Friday, December 18, 2009 5:40 PM
-
Friday, December 18, 2009 7:22 AMHello Shawn,
as Lekss wrote you can select the hostname and the used network protocol in a client session.
There is also a field "net_address", it looks & sounds like the MAC address of the client, but when I test & compare it, it don't fit. So I don't know, what this net_address represent.
SELECT hostname, net_library, net_address
FROM sys.sysprocesses
WHERE spid = @@SPID
Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich täglich http://olafhelper.over-blog.de -
Thursday, July 26, 2012 10:54 AM
1. You can get that from SQL server profiler trace files. open the trc files with SQL profiler where you can see the hostname , login name etc from here.
2. You can also look in to the sys.dm_exec_sessions the field hostname will give the computer name (or eventually the ip address).
Thanks, LeksIn shared hosting there is no right to execute from sys.dm_exec_sessions, so how to get client ip. Right query to get client-ip is mentioned below
SELECT client_net_address
FROM sys.dm_exec_connections
WHERE session_id = @@SPID; -
Thursday, August 23, 2012 10:16 PM
You can try out this solution. This code works even on sared hosting
http://dev-doc.blogspot.com/2012/08/ms-sql-2008-client-ip-address-on-shared.html

