How to deal with an invalid pooled connection?

It seems that, when this happens, the FireDAC driver first throws an EMSSQLNativeException exception, then the RO framework throws an EROUnregisteredServerException.

I’m try to trap one of these but without much success. Firstly, I can see the exceptions when running the server in the Delphi IDE, but when run outside the IDE, I don’t see any exception passed back to the client.

I’ve tried adding the code detailed in this item: How catch & log exceptions (Delphi)

But no ExceptObject is ever created.

UPDATE:

Sorry my mistake - had some old code which was eating the exception. The OnDeactivate handler now works as per the other article, although there appears to be no easy way to determine if the exception was due to a dead connection in the pool. I’ve had to resort to checking if the exception message contains the text SQL_ERROR as this is what the FireDAC driver seems to produce in this situation. If it does then I call ClearPool on the connection manager and then subsequent calls re-create the connection and all seems to work.