Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to delete the database user as the user is already logged in currently. error 15434

I have created the user sagar in SQL Server 2012 database and mapped it to the XYZ database. After some time I deleted the XYZ database and now I don't need the existing user sagar also. But when I try to delete the user from SQL Srever Management Studio. I am getting the following exception

Could not drop login 'sagar' as the user is currently logged in. error:15434

like image 524
Sagar Pudi Avatar asked Apr 28 '15 06:04

Sagar Pudi


People also ask

Could not drop login as the user is currently logged in 15434?

Microsoft SQL Server Error 15434 This error generates when a login has made a connection to the SQL Server Instance and you are trying to drop the same login. Solution to fix this issue is to close all sessions which are opened by this login and then drop it.

How do I delete users in SSMS?

If you are using SQL Server Management Studio you can browse to the user and right-click selecting delete.


1 Answers

User can be deleted after killing the session by identifying the session_id of the user.

SELECT session_id FROM sys.dm_exec_sessions WHERE login_name = 'sagar'  KILL 51  --51 is session_id here, you may get different id 

Now you can delete the login simply by executing the below query (or) by using sql server management studio options.

DROP LOGIN 'sagar' 
like image 159
Sagar Pudi Avatar answered Oct 06 '22 17:10

Sagar Pudi