SQL Server不像Mysql那样原生支持限制IP登录。
但可以使用Login触发器来实现。
以下为使用Login触发器实现限制用户u_user_r在指定IP192.168.1.205使用SSMS登录的Login触发器脚本:
CREATE TRIGGER [tr_connection_limit] ON ALL SERVER WITH EXECUTE AS 'sa' FOR LOGON AS BEGIN IF ( EXISTS( SELECT 1 FROM sys.dm_exec_sessions WHERE session_id = EVENTDATA().value('(/EVENT_INSTANCE/SPID)[1]', 'smallint') AND program_name like 'Microsoft SQL Server Management Studio%' ) AND ORIGINAL_LOGIN() = 'u_user_r' AND (SELECT EVENTDATA().value('(/EVENT_INSTANCE/ClientHost)[1]', 'nvarchar(20)'))='192.168.1.205' ) ROLLBACK; END;