开发者

How can i see what IP address made the request to SQL Server?

i need to clearly see what IP address made what sql query to SQL server. I am trying to use SQL Profiler, but it seems there is no way i can somehow to differentiate the machine (browser) where the query came from. It only has the comm开发者_开发问答unication details between the web server and the sql server. Is there ANY way for me (any unknown log?) that will allow me to see the identification of the original machine where the query came from?

Thanks for any suggestion.

HF


You can get the hostname of the current connection, or really any information from the sysprocesses table

SELECT hostname FROM sys.sysprocesses WHERE spid = @@SPID

This obviously won't work to get the ip address of web hosts if that's what you're looking for.


Like @joshperry said, you can retrieve client address and server address with

SELECT client_net_address, local_net_address 
FROM sys.dm_exec_connections 
WHERE session_id = @@SPID


As far as SQL Server is concerned the request will always come from your webserver. You need to capture and log the IP address in your web app.


SELECT r.client_net_address,sqltext.Text
  FROM sys.dm_exec_requests req left join sys.dm_exec_connections as r on req.session_id=r.session_id
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext


If you do not write code in the application to pass the client address from the web server to the database you will have to look at the web logs - they will give the ip address of the client.


SELECT * FROM sys.dm_exec_connections returns information about the connections established to this instance of SQL Server and the details of each connection (https://msdn.microsoft.com/en-us/library/ms181509%28v=sql.120%29.aspx)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜