ogun
ogun

Reputation: 1334

Trigger for Killed Sessions

I want to use a trigger when a session is killed / ended. Is it possible?

My program is connecting a table and update "online" field when it is online. If my program crashed or my mssql connection killed, i want to update "online" field...

For example: When my program is online, it gets spid and update SERVICE_TABLE(spid, online)

SEVICE_TABLE
------------
id
spid
online

when a session is killed / ended, trigger look up SERVICE_TABLE. Is killed spid in SERVICE_TABLE, update "online" field to false.

Upvotes: 1

Views: 1411

Answers (2)

Andomar
Andomar

Reputation: 238256

We have a similar situation. I've basically added a "lastseen" to our equivalent of the service table. A background process in the client updates this field every minute. (Be sure to create a new database connection every time you update the field.)

If the "lastseen" field is more than 5 minutes in the past, we assume the application has gone the way of the Hindenburg.

Upvotes: 2

Martin Smith
Martin Smith

Reputation: 453756

There are no DDL logout triggers in SQL Server (though there are login ones). Service Broker can be used to process the AUDIT_LOGOUT events though.

Does this help?

Upvotes: 1

Related Questions