Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Trying to delete Login from SQL Server, getting error

Posted on 2016-09-15
19
Medium Priority
?
207 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:Jamie Fellrath
[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
  • 7
  • 6
  • 5
19 Comments
 
LVL 52

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:Jamie Fellrath
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 52

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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
LVL 1

Author Comment

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

Author Comment

by:Jamie Fellrath
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 52

Accepted Solution

by:
Vitor Montalvão earned 580 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:Jamie Fellrath
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 27

Assisted Solution

by:Zberteoc
Zberteoc earned 1420 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 52

Expert Comment

by:Vitor Montalvão
ID: 41799884
Check in the SQL Server instance / Server Objects / Triggers. It's some trigger created there?
0
 
LVL 1

Author Comment

by:Jamie Fellrath
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 27

Assisted Solution

by:Zberteoc
Zberteoc earned 1420 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 52

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 580 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:Jamie Fellrath
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 27

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 27

Assisted Solution

by:Zberteoc
Zberteoc earned 1420 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 27

Assisted Solution

by:Zberteoc
Zberteoc earned 1420 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 27

Assisted Solution

by:Zberteoc
Zberteoc earned 1420 total points
ID: 41800398
0
 
LVL 27

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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 setup several different housekeeping processes for a SQL Server.

688 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