Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 DEV-Group
 DEV Discussions (General)
 Trapping connection problems
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

ROB
Junior Member

USA
347 Posts

Posted - 25 January 2003 :  13:36:02  Show Profile  Visit ROB's Homepage  Send ROB an AOL message  Send ROB an ICQ Message  Send ROB a Yahoo! Message
One of the downsides to have a site completely dependent (or nearly so) on database connectivity is that if the database is down or otherwise unavailable, your site spews various connection errors back at your visitors. Not a pretty site, and it could potentially encourage hackers (since they can see a bit about your code and database connection).

My question is this: How difficult would it be to add error trapping so that if for some reason the database is down, you could display some alternate, non-database-dependent web page? This page would probably apologize and explain that the site is down for maintenance or something similar.

Thoughts?

Jeff (ROB) Hester
BigBlueNetwork | BigBlueBall | Christian Church Today

Edited by - ruirib on 25 January 2003 13:49:55

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 25 January 2003 :  13:54:57  Show Profile  Visit D3mon's Homepage
Try running this code on every page right at the start:
on error resume next
Set DB = Server.CreateObject("ADODB.Connection")
DB.Errors.Clear
Err.Clear
With DB
.ConnectionString = strConnString
.Open
End With
If Err.Number = 0 Then
  'connection is fine
Else
  'bah, its down again, **** host!
End If
on error goto 0

For the else condition, I usually call a sub that display a suitable message.



Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 25 January 2003 :  14:10:49  Show Profile  Send ruirib a Yahoo! Message
This doesn't look too difficult. One way would be to develop a custom error page, which means you'd need to replace the default one used by IIS. You'd need to be able to access IIS manager to do it, which usually does not happen when you are hosted in someone else's server.

Another way would be to catch the error yourself, in your code. To stop the generic error handler to be executed when an error occurs you need to use a On Error Resume Next statement. This means that the code execution won't be stopped and that the statement following the one where you have the error will be executed. So, you'd need to add code to check for an error following every statement that could generate such an error.
With statements that access databases using ADO, you can check errors by examining the errors collection of the connection object:

     if my_conn.Errors.Count > 0 then
         realErrors = 0
         'Loop through the errors
         For Each objError in my_conn.Errors

           if objError.Number <> 0 then 'catching only error messages, not warnings or informational messages, where Number=0
               'Now you know this as an error related to the database access, you could do whatever you wanted, maybe showing 
               '  the text message or other info about the error. I'm just counting the real errors

               realErrors = realErrors + 1  ' increment the count
           end if
        Next  
          'Now you can test the number or real_errors and redirect to a different page, if  you want

          if realErrors > 0 then  Response.Redirect ("myDBErrorPage.asp")
      end If      


Hope this helps.


Snitz 3.4 Readme | Like the support? Support Snitz too

Edited by - ruirib on 25 January 2003 14:16:07
Go to Top of Page

ROB
Junior Member

USA
347 Posts

Posted - 25 January 2003 :  14:13:17  Show Profile  Visit ROB's Homepage  Send ROB an AOL message  Send ROB an ICQ Message  Send ROB a Yahoo! Message
Thanks! I'm going to try a redirect to a static and fairly generic page.

Seems like this would make a nice bit of core code for Snitz (hint, hint!).

Jeff (ROB) Hester
BigBlueNetwork | BigBlueBall | Christian Church Today
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 25 January 2003 :  14:13:18  Show Profile  Send ruirib a Yahoo! Message
Well spent a lotta time writing this and failed to catch the previous post by D3mon. It's a similar approach with some differences though, so I'm just gonna leave it anyway.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.22 seconds. Powered By: Snitz Forums 2000 Version 3.4.07