Posts

Showing posts from March, 2016

Log Entries that are hitting a table along with their IP and host name

CREATE TABLE dbo.LoggingTable (     LoggingID INT NOT NULL         CONSTRAINT PK_LoggingTable         PRIMARY KEY CLUSTERED         IDENTITY(1,1)     , AppName SYSNAME     , HostName SYSNAME     , ClientNetAddress VARCHAR(255)     , LogDateTime DATETIME ); GO CREATE TRIGGER dbo.triggername ON dbo.address_type /* name of the target table  */ FOR INSERT, UPDATE, DELETE AS BEGIN   INSERT dbo.LoggingTable(AppName, HostName, ClientNetAddress, LogDateTime)   SELECT app_name(), host_name(), client_net_address, SYSDATETIME()   FROM sys.dm_exec_connections dec   WHERE dec.session_id = @@SPID; END GO