This topic is locked

DB Error Trapping/

8/28/2011 11:21:15 PM
ASPRunnerPro Tips and tricks
R
Roger author

Long time no post, so here is an interesting one.
In asprunner (ASP version) the include file (aspfunctions.asp) has code to trap vbscript errors; sub name: ReportError (look for CALL aspfunctions.asp). It works well when it actually gets called and of course it queries the err.number and err.description ASP system vars. However in several procs within that script file, you need to place the following snippets:
Before ANY call to the db system, place "On Error Resume Next"

After ANY call to the db system, place a "On error goto 0" (that's a ZERO).
If you don't place them in the script file, the procedure will not get called as the ASP token interpreter has already trapped the error using it's built in error handler.
Also, remember that On Error Trapping is sub/func relative, so make sure that you don't fall into the common trap of placing an On Error Resume Next at the top of the script file, it must be placed in each proc/sub that you are executing or calling if you wish to trap errors.
In most cases, these snippets are there, however today when in a hotel, I did not have a connection to my SQL server and after 15 seconds (default time out), I received an ADODB connection error on the web page. Easy enough to fix (using the above).
However, this is definately not an error message you want to display on any page, hackers love this kind of clue.
Hope this trick (pointer) helps. If I've posted in the wrong area, my appologies.
Cheers.

K
Kevin 12/13/2011

I am trying to understand this: If there are errors in the database like FK issues, Missing tables/columns, or even if the database is dead -> Will this crash the application? I have my website in php. What about application and network related errors? Can these cases be caught for and have a work around without users seeing a non functionaning site or site down message?