Error Trapping Database Connections lazarus / 16-Databases ---------------------------------------------------------------------- timcs · 2016-07-07 08:10 Hi   My program connections to our work postgres database and because it runs alongside remote desktop connections, it writes records to a local database to indicate when a user is on and off a customer connection. This is all fine until one or more of these connections requires any kind of VPN whether it is a Windows VPN or other types.  Most of these VPNs are not that bad and still allow local connections to the database but some completely take the client PC off the local connection, when this happens , my program will fail to either connect or even sometimes be able to connect but not disconnect.  As the likely hood of these connections ever being changed is slim, I would like to make my program far more stable and instead of the "general" error about it not being able to write to the database and therefore often crash leaving an in transaction connection sitting on the database connection.  I have tried to use the try ... finally ..end but I must be doing something wrong when I use this because these errors still persist. Thanks TimCS ---------------------------------------------------------------------- Ñuño_Martínez · 2016-07-07 16:15 Quote from: timcs on July 07, 2016, 10:10:23 am I have tried to use the try ... finally ..end but I must be doing something wrong when I use this because these errors still persist.Not actually.  Don't assume that a TRY will handle every possible error. I recommend to you to do an in deep debug using GDB as it's more flexible than Lazarus' debugger.  You may find the bug in another place.  Also may be that the developer of the data base interface didn't use Exceptions correctly, or may be it handles them before it reachs your code, so you may receibe unspected information that should be checked instead of catch an exception. ---------------------------------------------------------------------- vfclists · 2016-07-07 16:33 Quote from: timcs on July 07, 2016, 10:10:23 amHi   My program connections to our work postgres database and because it runs alongside remote desktop connections, it writes records to a local database to indicate when a user is on and off a customer connection. This is all fine until one or more of these connections requires any kind of VPN whether it is a Windows VPN or other types.  Most of these VPNs are not that bad and still allow local connections to the database but some completely take the client PC off the local connection, when this happens , my program will fail to either connect or even sometimes be able to connect but not disconnect.  As the likely hood of these connections ever being changed is slim, I would like to make my program far more stable and instead of the "general" error about it not being able to write to the database and therefore often crash leaving an in transaction connection sitting on the database connection.  I have tried to use the try ... finally ..end but I must be doing something wrong when I use this because these errors still persist. Thanks TimCS Shouldn't that be a try .. except .. end? A try .. finally .. end is mainly for restoring state and releasing resources. You have to use a try .. except ..end to trap them and log them. ---------------------------------------------------------------------- timcs · 2016-07-07 16:43 Quote from: vfclists on July 07, 2016, 06:33:38 pmQuote from: timcs on July 07, 2016, 10:10:23 amHi   My program connections to our work postgres database and because it runs alongside remote desktop connections, it writes records to a local database to indicate when a user is on and off a customer connection. This is all fine until one or more of these connections requires any kind of VPN whether it is a Windows VPN or other types.  Most of these VPNs are not that bad and still allow local connections to the database but some completely take the client PC off the local connection, when this happens , my program will fail to either connect or even sometimes be able to connect but not disconnect.  As the likely hood of these connections ever being changed is slim, I would like to make my program far more stable and instead of the "general" error about it not being able to write to the database and therefore often crash leaving an in transaction connection sitting on the database connection.  I have tried to use the try ... finally ..end but I must be doing something wrong when I use this because these errors still persist. Thanks TimCS Shouldn't that be a try .. except .. end? A try .. finally .. end is mainly for restoring state and releasing resources. You have to use a try .. except ..end to trap them and log them. I probably mean try except .. end but I need to check if that is what I used. My main question is do I place all connections/disconnections lines between try and except or should I just use one as a test ? Quote from: Ñuño_Martínez on July 07, 2016, 06:15:28 pmQuote from: timcs on July 07, 2016, 10:10:23 am I have tried to use the try ... finally ..end but I must be doing something wrong when I use this because these errors still persist.Not actually.  Don't assume that a TRY will handle every possible error. I recommend to you to do an in deep debug using GDB as it's more flexible than Lazarus' debugger.  You may find the bug in another place.  Also may be that the developer of the data base interface didn't use Exceptions correctly, or may be it handles them before it reachs your code, so you may receibe unspected information that should be checked instead of catch an exception. I presume there is documentation on how to use GDB ? The only issue I have with testing is that I cannot actually test the program through any IDE because how it works , with parameters and at work itself. So I cannot actually run it on its own Thanks TimCS ---------------------------------------------------------------------- Ñuño_Martínez · 2016-07-13 10:52 To be sincere GDB looks a bit intimidate but actually it isn.  Here you have some tips.  The first two ones in the list should be enough to start with.  About parameters, are you talking about command line parameters? Sorry for the late answer.  I was bussy.