SQL 登入觸發程序
使用登入觸發程序稽核和控制伺服器工作階段,例如追蹤登入活動、限制登入 SQL Server,或限制特定登入的工作階段數。例如,在下列程式碼中,如果登入 sa 已經建立三個使用者工作階段,登入觸發程序就會拒絕該登入對 SQL Server 所起始的登入嘗試。
CREATE TRIGGER connection_limit_trigger
ON ALL SERVER WITH EXECUTE AS 'sa'
FOR LOGON
AS
BEGIN
IF ORIGINAL_LOGIN()= 'sa' AND
(SELECT COUNT(*) FROM sys.dm_exec_sessions
WHERE is_user_process = 1 AND
original_login_name = 'login_test') > 3
ROLLBACK;
END;
CREATE TRIGGER connection_limit_trigger
ON ALL SERVER WITH EXECUTE AS 'sa'
FOR LOGON
AS
BEGIN
IF ORIGINAL_LOGIN()= 'sa' AND
(SELECT COUNT(*) FROM sys.dm_exec_sessions
WHERE is_user_process = 1 AND
original_login_name = 'login_test') > 3
ROLLBACK;
END;
留言