Get Host Name from Client:
select HOST_ID(),HOST_NAME(),SUSER_NAME(),SUSER_SNAME()
------------------------------------------------------------------
Get Host Name from Client IP :
SELECT CONNECTIONPROPERTY('net_transport') AS net_transport,
CONNECTIONPROPERTY('protocol_type') AS protocol_type,
CONNECTIONPROPERTY('auth_scheme') AS auth_scheme,
CONNECTIONPROPERTY('local_net_address') AS local_net_address,
CONNECTIONPROPERTY('local_tcp_port') AS local_tcp_port,
CONNECTIONPROPERTY('client_net_address') AS client_net_address
Or
SQL 2005
SELECT *
FROM sys.dm_exec_connections
WHERE session_id = @@SPID
--------------------------------------------
CREATE TRIGGER [RestrictSSMSLogIn]
ON ALL SERVER WITH EXECUTE AS 'AppUser'
FOR LOGON
AS
BEGIN
IF ORIGINAL_LOGIN()= 'AppUser' AND
(SELECT TOP 1 Program_Name
FROM sys.dm_exec_sessions
WHERE is_user_process = 1
AND original_login_name = 'AppUser'
Order By Session_Id Desc)
<>'Microsoft SQL Server Management Studio' and
(SELECT TOP 1 Program_Name
FROM sys.dm_exec_sessions
WHERE is_user_process = 1
AND original_login_name = 'AppUser'
Order By Session_Id Desc)<> 'Microsoft SQL Server Management Studio - Query'
ROLLBACK;
END
GO
No comments:
Post a Comment