Skip to content

Instantly share code, notes, and snippets.

@AshFlaw
Created October 16, 2017 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AshFlaw/4935fc20494149fdfde36c3e7f3f15f5 to your computer and use it in GitHub Desktop.
Save AshFlaw/4935fc20494149fdfde36c3e7f3f15f5 to your computer and use it in GitHub Desktop.
Create the trigger to log connection details to the User IP Audit table.
USE UserIPAudit
GO
CREATE TRIGGER LogonTrigger ON ALL SERVER FOR LOGON
AS
BEGIN
DECLARE @data XML
SET @data = EVENTDATA()
INSERT INTO UserIPAudit.dbo.[UserIPLog]
(
[LoginName],
[ClientHost],
[LoginType],
[AppName],
[FullLog]
)
VALUES
(
@data.value('(/EVENT_INSTANCE/LoginName)[1]', 'nvarchar(max)'),
@data.value('(/EVENT_INSTANCE/ClientHost)[1]', 'varchar(50)'),
@data.value('(/EVENT_INSTANCE/LoginType)[1]', 'varchar(100)'),
APP_NAME(),
@data
)
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment