I'm currently using Change Data Capture (CDC) to track data changes, and I wish to track the host name and IP address of the client submitting the query that made the changes. If there are 5 different clients logged in via the same user name, one faces the conundrum of tracking which of the 5 fired the query. Other specious solutions that I found include altering the CDC table with following command:
ALTER TABLE cdc.schema_table_CT
ADD HostName nvarchar(50) NULL DEFAULT(HOST_NAME())
However, this returns the host-name of the server on which the query was fired, and not the host-name of the client that fires the query.
Is there a way around this problem? Something that would help to log the host-name or the IP address (or some other kind of unique identity) of the client.
I do not want to use triggers, as it slows down the system, also CDC generates system tables, so having a trigger on that is apparently not possible.
Best Answer
I am not sure about CDC, but if the login has
view server state permission
you can use DMVs to get some information.This is given in Books Online here. I changed the query to add columns which would give you the
IP address
: