Limit number of user logins in SQL Server 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') &gt; 2
    ROLLBACK;
END;
Logon triggers are special. Not going too far into it, they must exist in the master database and not any other, thus the answer to your question is: "It can't."

https://msdn.microsoft.com/en-us/library/bb326598.aspx

-Sean