Solved

Alert mechanism if there is a particular login attempted in SQL server

Posted on 2016-10-25
3
42 Views
Last Modified: 2016-11-04
Hi there,
  Is there any way i could get alert from SQL server if the particular login is attempted in SQL server?

Eg., particular User named "Robin" attempts to login SQL server , then can i setup an Alert mechanism which should send an email to me stating "Robin" has logged in to our database server.

If yes, please share me the scripts/steps to setup the same.

Note: My environment running with SQL server 2008 R2 service pack 2 enterprise edition.

thanks
Deepak
0
Comment
Question by:Deepak Kumar
3 Comments
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41859804
You can create a script and their you can check the name, Name of the user you can get like...


SELECT SUSER_NAME()  

GO  

O/P

XXX\pawankhowal
0
 
LVL 48

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 41859913
The mechanism that you want is Logon Trigger. With that you can test the login name and send an email if it matches what you want. Something like:
CREATE TRIGGER login_check ON ALL SERVER 
FOR LOGON  
AS  
BEGIN  
IF ORIGINAL_LOGIN()= 'Robin' 
    EXEC msdb.dbo.sp_send_dbmail  
        @profile_name = 'SQL Server',  
        @recipients = 'firstname.lastname@companyname.com',  
        @body = 'Robin just logged in SQL Server',  
        @subject = 'Logon' ; 
END;

Open in new window

0
 

Author Closing Comment

by:Deepak Kumar
ID: 41873608
Thanks Vitor for your help
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question