SQL SERVER – Fix : Msg 15151, Level 16, State 1, Line 3 Cannot drop the login ‘test’, because it does not exist or you do not have permission

I got following error when I was trying to delete user ‘test’ with ‘SA’ login. I was little surprised but then I tried to delete with the windows authenticated systemadmin account. Once again I got the same error.

Msg 15151, Level 16, State 1, Line 3
Cannot drop the login ‘test’, because it does not exist or you do not have permission.

The reason I was surprised that I was systemadmin and I should be allowed to delete the login. I am including the script which I used to delete the account here.

IF EXISTS (SELECT * FROM sys.server_principals WHERE name = N'Test')
DROP LOGIN [Test]

Fix/Workaround/Solution:

I finally found out that error was misleading. I had another session open in SQL Server Management Studio with username ‘test’ and it was preventing me to drop the user. Once I closed that open session I was successfully able to delete the user using above script.

In Normal Case:
Following error usually show up when user is logged in, which I did not get it.
Msg 15434, Level 16, State 1, Line 3
Could not drop login ‘test’ as the user is currently logged in.

However, when I tried to re-create scenario I got above error. I want to share this experience with users and want to know if they have ever faced this scenario.

Reference : Pinal Dave (http://blog.sqlauthority.com)

8 thoughts on “SQL SERVER – Fix : Msg 15151, Level 16, State 1, Line 3 Cannot drop the login ‘test’, because it does not exist or you do not have permission

  1. had the same problem. can’t seem to find a solution to it though. the phantom user is still logged on! It’s definitely another SQL2008 bug!

    Like

  2. Dear Pinal,
    Thanks for your sharing ,
    Msg 15434, Level 16, State 1, Line 3
    Could not drop login ‘test’ as the user is currently logged in.
    in this error that you’ve mentioned above, I share this solution :
    1.
    select * from sys.dm_exec_sessions WHERE login_name = ‘test’
    2.
    KILL session_id
    3.
    DROP LOGIN [Test]

    Sincerely yours,
    Saeed

    Like

  3. Pingback: SQL SERVER – Weekly Series – Memory Lane – #009 « SQL Server Journey with SQL Authority

  4. Right here is the perfect blog for anybody
    who really wants to find out about this topic. You realize a whole lot
    its almost tough to argue with you (not that I personally will
    need to…HaHa). You certainly put a new spin on a topic that has been
    discussed for years. Great stuff, just great!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s