Solved

Trying to delete Login from SQL Server, getting error

Posted on 2016-09-15
19
39 Views
Last Modified: 2016-11-02
Hi all,

I'm trying to delete a user from our MS SQL Server 2008 (yeah, I know) database server.  The user in question has left the organization and is no longer in Active Directory, but apparently his name is still all over the place.  

I've removed him from every database, and now I'm trying to delete him in SSMS in Object Explorer via <database name>/Security/Logins. It's giving me the following error:  

The server principal is set as the execution context of a trigger or event notification and cannot be dropped. (Microsoft SQL Server, Error: 15186)

I've removed him everywhere I could find him - jobs, etc.  Anyone have any other ways to find what setting he might be in, still? I've tried a  couple of queries from TechNet and such (example: https://social.technet.microsoft.com/Forums/en-US/3a337af8-cc60-4c66-a475-bd0965576545/the-database-principal-is-set-as-the-execution-context-of-one-or-more-procedures-?forum=sqlsecurity) but haven't found anything that helps yet.
0
Comment
Question by:jfellrath
  • 7
  • 6
  • 5
19 Comments
 
LVL 46

Expert Comment

by:Vitor Montalvão
ID: 41799780
I never liked to use the GUI to perform those kind of tasks.
Try to open a new query window and run the following command:
DROP LOGIN [Domain\login_name]

Open in new window

0
 
LVL 1

Author Comment

by:jfellrath
ID: 41799811
Thanks Vitor!

This doesn't seem to be working - apparently because the Login includes a backslash (due to its being an Active Directory login with domain specified).  The SQL doesn't care for the backslash.
0
 
LVL 46

Expert Comment

by:Vitor Montalvão
ID: 41799815
Can you provide a print screen of the login in the SQL Server security / login folder?
0
 
LVL 1

Author Comment

by:jfellrath
ID: 41799842
Do you mean the "Properties" window?
0
 
LVL 1

Author Comment

by:jfellrath
ID: 41799851
Here's the screen print fragment of the login:  

btempleton.png

Is this what you mean? I'm sorry, but I'm not comfortable showing more than this login.
0
 
LVL 46

Accepted Solution

by:
Vitor Montalvão earned 145 total points
ID: 41799855
Sure. It's that login that's important for this question.
So you ran this? DROP LOGIN [OTTA\btempleton]

If affirmative what was exactly the error message?
0
 
LVL 1

Author Comment

by:jfellrath
ID: 41799867
Thanks, same error:  

Msg 15186, Level 16, State 1, Line 1
The server principal is set as the execution context of a trigger or event notification and cannot be dropped.
0
 
LVL 26

Assisted Solution

by:Zberteoc
Zberteoc earned 355 total points
ID: 41799871
It seems that there is a trigger in the database that is executed impersonating this user or there is a job created that it owns or setup for email notification. You will have to look in all these places and make sure you remove/replace any reference to it. You also have to remove the user form ALL the databases.
1
 
LVL 46

Expert Comment

by:Vitor Montalvão
ID: 41799884
Check in the SQL Server instance / Server Objects / Triggers. It's some trigger created there?
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 1

Author Comment

by:jfellrath
ID: 41799911
Thanks Zberteoc. I've got him removed from all the databases already, including the system databases. I also checked the jobs... at least for him as the owner (and found a couple and changed the owner).  I'll check around more for the email notifications.

Vitor - I see a trigger there but don't see how to find the owner of it.
0
 
LVL 26

Assisted Solution

by:Zberteoc
Zberteoc earned 355 total points
ID: 41799919
In a trigger you can have something like:

CREATE TRIGGER trg_name ON tbl_name
WITH EXECUTE AS 'user'
for insert, update
...

If you can't see anything like that you are safe. Error is caused by those agent ownership and maybe email notifications for jobs.
0
 
LVL 46

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 145 total points
ID: 41799991
Yes, must be the EXECUTE AS in some trigger or event notification. Check if some of those objects has it.
0
 
LVL 1

Author Comment

by:jfellrath
ID: 41800319
I used our Redgate SQL Search tool to look for his name anywhere - and aside from notes made in old procedure code and the like, I'm not seeing anything. Assuming that the Triggers we're talking about are coded as owned in the EXECUTE AS clause, then I think we've exhausted that possibility.  

What about event notifications? Where might I look to find some of that stuff?
0
 
LVL 26

Expert Comment

by:Zberteoc
ID: 41800378
Look for the login name, specifically, but only for the btempleton part.

For notification look In the jobs. The jobs have Notification in case of failure and those can be tight with accounts. I am not 100% if are in connection with logins or just emails but you can check in the jobs' Properties and then in Alerts or Notification.
0
 
LVL 26

Assisted Solution

by:Zberteoc
Zberteoc earned 355 total points
ID: 41800394
Also you can try this, if you haven't yet. Maybe you missed something:

http://www.jasonstrate.com/2013/07/security-questions-removing-logins-from-databases/
0
 
LVL 26

Assisted Solution

by:Zberteoc
Zberteoc earned 355 total points
ID: 41800396
This will help you to find jobs with a certain owner:

SELECT j.name
FROM msdb.dbo.sysjobs AS j
INNER JOIN sys.syslogins AS l ON j.owner_sid = l.sid
WHERE l.name = 'loginYouWantToDelete'
0
 
LVL 26

Assisted Solution

by:Zberteoc
Zberteoc earned 355 total points
ID: 41800398
0
 
LVL 26

Expert Comment

by:Zberteoc
ID: 41822342
Please give some feedback, award points if the answers were helpful or close this question if not.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

910 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now