Solved

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

Posted on 2016-10-25
3
45 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 49

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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Select - Help finding duplicate records 5 21
Upgrading to SQL Server 2015 Express 2 36
SQL- GROUP BY 4 25
mysql vs miscrosoft sql server 6 19
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

726 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