I need to trace on SQL SERVER authenticated user whenever he/she is logging in to the system, automatically send alert mail like this user is login with this IP and this time.
I have just one solution for this problem but this is not so proper because i have to see that manually.
Below solution is not work for alert mail because i have to run manually.
SELECT
DISTINCT
@@SERVERNAME ServerName ,
DB_NAME(database_id) DatabaseName ,
s.login_name ,
s.[host_name] ,
c.client_net_address ,
c.connect_time
FROM sys.dm_exec_connections AS c
INNER JOIN sys.dm_exec_sessions AS s ON c.session_id = s.session_id
WHERE c.auth_scheme = 'SQL'
AND program_name IN ( 'Microsoft SQL Server Management Studio',
'Microsoft SQL Server Management Studio - Query' )
AND c.connect_time >= DATEADD(DAY, -1, GETDATE())
AND login_name <> 'prcommon';
Thanks.