below the Database name is always blank
I am trying to get Database Name in a Logon Trigger using EVENTDATA() but its not working and it appears like the EVENTDATA() is not working at all, I am trying to block users who are using excel to query the 'TestDB'. Can someone tell me what I am doing wrong with this code.
CREATE TRIGGER tr_block_excel_users ON ALL SERVER FOR LOGON AS
declare @data XML declare @DatabaseName as varchar(128)
SET @data = EVENTDATA(); set @DataBaseName = @data.value('(/EVENT_INSTANCE/DatabaseName)[1]', 'nvarchar(128)')
BEGIN IF (select @DatabaseName) = 'TestDB' and ORIGINAL_LOGIN() <> N'xx\xxxxxxxex' AND APP_NAME() LIKE '%Microsoft Office%' OR APP_NAME() LIKE '%EXCEL%' ROLLBACK; END
I expected the name of the database using EVENTDATA(), but getting a blank database name,