Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

Trying to delete Login from SQL Server, getting error

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
Jamie Fellrath
Asked:
Jamie Fellrath
  • 7
  • 6
  • 5
7 Solutions
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
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
 
Jamie FellrathApplication Developer/Data AnalystAuthor Commented:
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
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Can you provide a print screen of the login in the SQL Server security / login folder?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Jamie FellrathApplication Developer/Data AnalystAuthor Commented:
Do you mean the "Properties" window?
0
 
Jamie FellrathApplication Developer/Data AnalystAuthor Commented:
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
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
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
 
Jamie FellrathApplication Developer/Data AnalystAuthor Commented:
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
 
ZberteocCommented:
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
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Check in the SQL Server instance / Server Objects / Triggers. It's some trigger created there?
0
 
Jamie FellrathApplication Developer/Data AnalystAuthor Commented:
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
 
ZberteocCommented:
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
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Yes, must be the EXECUTE AS in some trigger or event notification. Check if some of those objects has it.
0
 
Jamie FellrathApplication Developer/Data AnalystAuthor Commented:
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
 
ZberteocCommented:
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
 
ZberteocCommented:
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
 
ZberteocCommented:
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
 
ZberteocCommented:
Please give some feedback, award points if the answers were helpful or close this question if not.
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

  • 7
  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now