I need a way to know when a session closes in SQL Server so I can clean up any resources allocated for that session by running a stored procedure I have.
When things are running perfectly, the client app would call a Cleanup
routine to do this. But if the user gets disconnected unexpectedly, I need something on the server to know ... and call the cleanup.
Thinking in terms of languages like VB or Delphi, I would register an event handler for this.
I see that SQL Server has 'Extended Events' but I have not figured out how to react to those events in a stored procedure or trigger...
Or is there some other way to capture a SessionClose
and then call a stored procedure?