I have the exact Query Text and the exact time & date the Query was executed, how can I find the Host Name that executed this query?
I'm using SQL Server 2008.
I have the exact Query Text and the exact time & date the Query was executed, how can I find the Host Name that executed this query?
I'm using SQL Server 2008.
Do you need @@SERVERNAME
SELECT @@SERVERNAME
will return the server name where the query was executed.
HOST_NAME
will return the workstation name
SELECT HOST_NAME()
You can check with HostName() as
SELECT HOST_NAME() AS HostName, SUSER_NAME() LoggedInUser
http://blog.sqlauthority.com/2009/05/26/sql-server-find-hostname-and-current-logged-in-user-name/
or
SELECT @IP_Address = client_net_address
FROM sys.dm_exec_connections
WHERE Session_id = @@SPID;
How to get the client IP address from SQL Server 2008 itself?
How to identify the caller of a Stored Procedure from within the Sproc
There is not any table with historical information about the host that executed a query - http://www.sqlservercentral.com/Forums/Topic1334479-146-1.aspx
This is as close as you'll get, I believe:
select host_name()
As is mentioned in the docs: "The client application provides the workstation name and can provide inaccurate data. Do not rely upon HOST_NAME as a security feature."