create trigger [connection_limit_TRG]
on all server with execute as 'sa'
for logon as
begin
if ORIGINAL_LOGIN() = 'op' and
(select count(*) from sys.dm_exec_sessions a join sys.dm_exec_connections b
on a.session_id = b.session_id
where is_user_process = 1 and original_login_name = 'another') > 0
begin
rollback;
end
end;
select a.session_id, original_login_name
from sys.dm_exec_sessions a join sys.dm_exec_connections b
on a.session_id = b.session_id
where is_user_process = 1 and original_login_name = 'another'
我解决了这个问题。这是更正后的触发器主体:
值得注意的是,由于某些原因,断开连接时会话没有关闭,所以如果遇到这样的问题,则需要使用以下命令手动关闭它们
kill
:another
可以使用以下查询查看会话列表(在我的情况下为 user ):如果这不起作用,那么您的用户可能没有查看服务器状态的权限。可以使用以下命令授予权限:
my_login - 您要授予权限的登录名。