CREATE TRIGGER [IP2user_block]
ON ALL SERVER 
FOR LOGON
AS
BEGIN
/* Логирование отработки тригера
DECLARE @IP NVARCHAR(MAX)=(SELECT DISTINCT client_net_address FROM sys.dm_exec_connections WHERE session_id = @@SPID);
DECLARE @body1 NVARCHAR(MAX)='Login: ' + ORIGINAL_LOGIN() + 'IP: ' + @IP; */


IF ORIGINAL_LOGIN()!= 'User' AND (SELECT DISTINCT client_net_address FROM sys.dm_exec_connections WHERE session_id = @@SPID)='xxx.xxx.xxx.xxx'
BEGIN
ROLLBACK;
INSERT INTO test.dbo.test2 (test) values (@body1);
END;
END;

GO
SET ANSI_NULLS OFF
GO

SET QUOTED_IDENTIFIER OFF
GO

ENABLE TRIGGER [IP2user_block] ON ALL SERVER
GO

Комментарии ()