I have a user login named 'manager' currently logged in PC1, I want to prevent this user from login in PC2. So I created a trigger, and I got an error
Msg 4621, Level 16, State 10, Line 2
Permissions at the server scope can only be granted when the current database is master
It works well if I use database master, but I want to use database
Employee. How can I fix it?
USE Employee; GO GRANT VIEW SERVER STATE TO manager; GO CREATE TRIGGER connection_limit_trigger2 ON ALL SERVER WITH EXECUTE AS 'manager' FOR LOGON AS BEGIN IF ORIGINAL_LOGIN()= 'manager' AND (SELECT COUNT(*) FROM sys.dm_exec_sessions WHERE is_user_process = 1 AND original_login_name = 'manager') > 2 ROLLBACK; END;