Could Not Drop Login Because the User Is Currently Logged In (Error 15434)

🚨Part of the SQL Server Errors series, the exact messages and what actually causes them.Related pillar: Security

Msg 15434 means the login you are dropping still has a session open. Disabling it will not clear that session, so find it, end it, and expect 2 more errors behind it if the login owns anything.


What Msg 15434 Says

Msg 15434  ·  Level 16  ·  State 1
Could not drop login 'AppLogin' as the user is currently logged in.
⚡Disable the login, end its sessions with KILL, then drop it. Find the sessions first, because ending them rolls back whatever they had open, and check what the login owns before the drop or it fails again.

DROP LOGIN will not remove a login while any session is connected as it, and it does not wait: it fails straight away. This is a decommission-day error. The account is being retired, but an application server, a scheduled task or a forgotten SSMS window is still using it.


Find the Sessions

SELECT s.session_id,
       s.host_name,
       s.program_name,
       DB_NAME(s.database_id) AS database_name,
       s.status,
       s.last_request_end_time
FROM sys.dm_exec_sessions AS s
WHERE s.login_name = N'AppLogin'
ORDER BY s.last_request_end_time;

The host_name and program_name are the useful columns. They tell you which server and which application still had the account, and that is a conversation to have before the login goes, not after. If nobody can say what the account is used for, run Create Decommission Audit Session for a few days first and let it record every connection.

SSMS query on sys.dm_exec_sessions returning the session still connected as the login

Disabling It Does Not End the Session

Disabling the login is the right first step, because it stops new logins. It does nothing to a session that is already connected. Measured on SQL Server 2025: after ALTER LOGIN ... DISABLE the session was still there, still running, and the drop failed with the same 15434.

ALTER LOGIN AppLogin DISABLE;
ALTER LOGIN DISABLE succeeds but DROP LOGIN fails with Msg 15434 while the user is logged in

Do it anyway, before the next step. Without it, an application connection pool reconnects the moment you end its session, and you are back where you started. With it, the reconnect fails with Login Failed: The Account Is Disabled (Error 18470), and the application’s own log shows who still needed the account.


End the Sessions, Then Drop

DECLARE @sql nvarchar(max) = N'';

SELECT @sql += N'KILL ' + CAST(s.session_id AS nvarchar(10)) + N';'
FROM sys.dm_exec_sessions AS s
WHERE s.login_name = N'AppLogin';

PRINT @sql;  -- read it before you run it
EXEC (@sql);

DROP LOGIN AppLogin;

A killed session rolls back any transaction it had open, and the client sees Cannot continue the execution because the session is in the kill state. In the lab the session went straight away, and the drop moved on to its next check: what the login owns. How to Kill a SPID covers watching a long rollback if the session was mid-way through something large.

KILL batch ending the login's sessions, then DROP LOGIN failing with Msg 15174 because the login owns a database

What the Login Owns

With the sessions gone, the drop fails again if the login owns anything. A login that owns a securable, a server-level object or an Agent job cannot be dropped. On SQL Server 2025 a login owning a database and a job failed on the database first, then on the job:

Msg 15174  ·  Level 16  ·  State 1
Login 'AppLogin' owns one or more database(s). Change the owner of the database(s) before dropping the login.
Msg 15170  ·  Level 16  ·  State 1
This login is the owner of 1 job(s). You must delete or reassign these jobs before the login can be dropped.

Check both before you start, so the drop works first time:

SELECT N'database' AS owns, d.name
FROM sys.databases AS d
WHERE d.owner_sid = SUSER_SID(N'AppLogin')
UNION ALL
SELECT N'agent job', j.name
FROM msdb.dbo.sysjobs AS j
WHERE j.owner_sid = SUSER_SID(N'AppLogin');

Then hand each one to a login that is staying:

ALTER AUTHORIZATION ON DATABASE::YourDb TO sa;

EXEC msdb.dbo.sp_update_job
     @job_name = N'Nightly Export',
     @owner_login_name = N'sa';

SQL Server will not drop a login that owns a job, so the drop itself is safe. A Windows account deleted in Active Directory gets no such check: its jobs fail at their next run with Unable to Determine if the Owner of Job Has Server Access (Error 15404). Reassign the jobs either way.

Query listing the database and Agent job the login owns, reassigned to sa before DROP LOGIN

The Drop Leaves Its Database Users Behind

When DROP LOGIN finally succeeds it says nothing about the databases. In the lab, the login’s user in a database it was mapped to was still there afterwards, now with no login behind it. That is an orphaned user, and recreating the login does not reattach it, because the new login gets a new SID. Mapping the user to a login with ALTER USER ... WITH LOGIN does reattach it, and that fix is in User, Group or Role Already Exists in the Current Database (Error 15023). Get Orphaned Users lists them across every database, and dropping one that owns a schema stops on The Database Principal Owns a Schema (Error 15138).

The order that works first time, then: disable the login, find and end its sessions, reassign the databases and jobs it owns, drop it, and clean up the users it leaves. Anything that still tries the account after that fails with Login Failed for User (Error 18456), State 5 in the error log, and the log line carries the client address, which tells you what you missed.


Frequently Asked Questions

I disabled the login and it still says currently logged in.
Disabling only stops new logins. The session that was already connected stays until it disconnects or you end it with KILL.
Will KILL lose somebody’s work?
Any open transaction in that session is rolled back. Read the session list first, so you know which server and application you are cutting off.
Does DROP LOGIN remove the database users?
No. The users stay in each database with no login behind them, as orphaned users. Drop them separately once the login is gone.
Can I just disable the login and leave it?
Yes, and on a decommission it is often the safer first stage: disable it, wait out a reporting cycle in case something still needs it, then drop. The sessions and ownership steps are the same when you do.

Where To Go Next

Retiring a login touches sessions, ownership and every database it was mapped to:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *