Created a Temporary users for testing purposes . But not able to remove the user in Microsoft SQL server Management Studio.
Error :
Could not drop Login as the user is currently logged in. (Microsoft SQL server,Error: 15434)
Drop Failed for Login (Microsoft.Sqlserver.smo)
Additional Information:
An exception while executing a Transact-SQL statement or batch.
(Microsoft.Sqlserver.Connectioninfo)
Solution –
Step 1 – Get the session ID (ENTER Login name in below)
SELECT session_id FROM sys.dm_exec_sessions WHERE login_name = 'Enter the login name you are trying to remove'
Step 2 – Enter the session ID like below to kill the existing sessions (Mine is 323)
SELECT session_id FROM sys.dm_exec_sessions WHERE login_name = 'Enter the login name you are trying to remove' KILL 323
Step 3 – Remove User
Now you should be able to remove the user.
Good to know-
To Take Database Offline Immediately. Killing all existing connections.
USE master GO ALTER DATABASE databasename SET OFFLINE WITH ROLLBACK IMMEDIATE GO