Solved

Trying to delete Login from SQL Server, getting error

Posted on 2016-09-15
19
32 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 45

Expert Comment

by:Vitor Montalvão
Comment Utility
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
Comment Utility
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 45

Expert Comment

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

Author Comment

by:jfellrath
Comment Utility
Do you mean the "Properties" window?
0
 
LVL 1

Author Comment

by:jfellrath
Comment Utility
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 45

Accepted Solution

by:
Vitor Montalvão earned 145 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 45

Expert Comment

by:Vitor Montalvão
Comment Utility
Check in the SQL Server instance / Server Objects / Triggers. It's some trigger created there?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:jfellrath
Comment Utility
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
Comment Utility
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 45

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 145 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 26

Expert Comment

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

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

In this article I will describe the Detach & Attach 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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

763 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

7 Experts available now in Live!

Get 1:1 Help Now