HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Kick a single user out of the database

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
theuserdatabasesinglekickout

Problem

I've seen multiple answers about kicking all of the other users but is there a way to stop the process id and kick just one user out of the database. Eg. user A B and C are connected to the database trying to generate reports but I only want C to stop and disconnect while A and B are still able to continue with their processes.

Solution

As a one-off you can use EXEC sp_who or EXEC sp_who2 or similar to find the SPIDs of that user's connections and then use KILL to stop them. Be aware that any transactions they have open in which changes have been made will need to be rolled back which could potentially take some time and be I/O intensive, but if they are just running reports the effect of this should be minimal. To stop them immediately restarting the processes disable their access before doing this (using ALTER LOGIN DISABLE or by adjusting their access rights more granularly).

If you find yourself needing to do this regularly you could write a procedure to automate the task, so you could just run EXEC kick_user_off '';, though if you need to do this sort of thing regularly enough for it to be worth the effort automating then I suspect you have a process and/or user problem that needs fixing of which this is just a symptom.

Context

StackExchange Database Administrators Q#126197, answer score: 7

Revisions (0)

No revisions yet.