Session and execution monitoring
SPID, query_id, read processes, maintenance tasks and cooperative cancellation.
Identifiers and monitoring domains
SPID identifies a SQL session or execution, query_id correlates application exchanges and WorkerPID maps work to a process. Maintenance jobs use a separate identifier space. Activity analysis should associate identity, database, duration and task kind to distinguish user load, result production and background work.
Inspect activity
EXEC sp_who2 returns SPID, Status, Login, DBName, QueryID, ElapsedMs, Command, Kind and WorkerPID. active omits sleeping connections. admin sees other identities and registered background tasks; ordinary users see only their own activity. Authenticated GET /api/sessions adds capacity and reader-pool state.
EXEC sp_who2;
EXEC sp_who2 active;Cancel the intended operation
KILL takes an active query’s numeric SPID, not a Windows PID. Users may cancel their own queries; admin may cancel others. HTTP uses query_id and the same identity on cancel. Maintenance jobs have their own IDs and cooperative cancellation. Do not indiscriminately terminate every python.exe on the server.
-- Replace 123 with a SPID observed in sp_who2:
KILL 123;After cancellation or client loss
Cancellation requests stopping; it does not restore initial state. A write or script prefix may already be published. Close the cursor afterward; produced packets may remain. Silently lost connections expire if no write detected disconnection. Coordinator CPU alone does not describe total server activity.