Assonet River Design Group : Portfolio : Code Snippets : Contact

Database Downtime Alert for Dreamweaver UltraDev.

Sample Dialog Screen:


Sample Code:

-- don't have UltraDev - or just want the code? then copy below and paste into a blank .asp page --

<%@LANGUAGE="VBSCRIPT"%>
<%
on error resume next '* this will ignore the error and continue

Dim oConn, sConnString, objCDO
set oConn = Server.CreateObject("ADODB.Connection")
sConnString = "clients_daveanddave"
Set objCDO = Server.CreateObject("CDONTS.NewMail")

'*open the database connection (it's really testing the connection)
oConn.Open(sConnString)
'* now if there was any database error such as too many client tasks or unspecified error, then it will ignore and goto next line since we declared on error resume next on top
'* check if there was error
if Err.Number <> 0 then
Response.write ("sorry. our database is down")

' *** Set A Cookie if there is an error and send email to Webmaster
' *** using cookie to limit number of emails each day/session
if Request.Cookies("ServerStatus") <> ("Down") Then
Response.Cookies("ServerStatus") = ("Down")
'Response.Cookies("ServerStatus").Expires = Date + 1

' *** Send Mail With CDO
objCDO.From = "webserver@yourdomain.com"
objCDO.To = "the database went down again - call the Web Hosting company ASAP!"
objCDO.CC = ""
objCDO.Subject = "Database is down"
objCDO.Body = "webmaster@yourdomain.com" & vbcrlf&_
"URL=" & Request.ServerVariables("URL") & vbcrlf&_
"HTTP User=" & Request.ServerVariables("HTTP_USER_AGENT")& vbcrlf&_
"-- End Alert Message --"
objCDO.Send()
Set objCDO = Nothing
End If
'* don't forget to release the connection object!
oConn.close
Set oConn=nothing
Response.End
'* the code or contents below will not be executed or shown
end if

'* now change the error handler so that if there's other errors, it will show the error and not ignore them
on error goto 0
'* if we are here, that means that we can access the database
'* so your first html or asp codes goes below
%>