<%@Language=VBScript%> <%Response.Buffer = True%> Oops... <% On Error Resume Next strApplication = Application("AppName") if strApplication = "" then strApplication = "Unspecified, please fix - SQL Admin" strQueryString = Request.QueryString if strQueryString = "" then strQueryString = "None" strForm = Request.Form if strForm = "" then strForm = "None" set objError = Server.getLastError() strNumber = objError.AspCode strSource = objError.Category strPage = objError.File strDesc = objError.Description strCode = Server.HTMLEncode(objError.Source) if strCode = "" then strCode = "No code available" strLine = ObjError.Line strASPDesc = ObjError.ASPDescription strRemoteAddr = Request.ServerVariables("REMOTE_ADDR") strRemoteHost = Request.ServerVariables("REMOTE_HOST") strLocalAddr = Request.ServerVariables("LOCAL_ADDR") set rs = Server.CreateObject("ADODB.Recordset") set Conn = Server.CreateObject("ADODB.Connection") conn.ConnectionString = Application("ErrorLogging") conn.open rs.Open "ErrorLog", conn, adOpenDynamic, adLockOptimistic, adCmdTable rs.AddNew 'The datetime is set on the SQL Server as a default value of getdate() rs("er_number") = strNumber rs("er_source") = strSource rs("er_page") = strPage rs("er_desc") = strDesc + ". " + strASPDesc rs("er_code") = strCode rs("er_line") = strLine rs("er_remote_addr") = strRemoteAddr rs("er_remote_host") = strRemotehost rs("er_local_addr") = strLocalAddr rs("req_querystring") = strQueryString rs("req_form") = strForm rs("application") = strApplication rs.Update %>
An error has occured.  Bob has been notified.
Description:<%=strDesc%>.
<%=strASPDesc%> 
Line:<%=strLine%> 
File:<%=strPage%> 
Code:<%=strcode%> 
Source:<%=strSource%> 
Remote Address:<%=strRemoteAddr%> 
Remote Host:<%=strRemoteHost%> 
Local Address:<%=strLocalAddr%> 
Error Number:<%=strNumber%> 
QueryString (Testing):<%=strQueryString%> 
Form Vars (Testing):<%=strForm%> 
<% set rs = nothing set conn = nothing set objError = nothing SendErrorEmail "Most Likely Stupid Coding Error", strSource, strNumber, strDesc 'Function to send an alert email 'Script from http://www.aspalliance.com/brettb/ErrorReportEmailer.asp 'Parameters used are: ' ErrorType = The type of error (e.g. "ASP Error") ' ErrorSource= Error source ' ErrorNumber = Error number ' ErrorDescription= Error description ' 'Changes required if you wish to use this script: ' '1. Change the constant declarations so the email goes to you! ' '2. If you disable session state then you must comment out the ' part of the script that extracts the details of the Session object ' '3. If you want to use a mail sending object other than ASPMail you need to ' alter the mail sending part of the script Function SendErrorEmail(ErrorType, ErrorSource, ErrorNumber, ErrorDescription) 'On Error Resume Next 'Declare variables Dim HTML 'The HTML to send in the email Dim CollectionItem Dim iNumber Dim myMail 'Mail Server Component Dim QS Dim RF 'Transfer the contents of the QueryString and Form collections to variables Set QS = Request.QueryString Set RF = Request.Form 'Declare constants. YOU MUST CHANGE THESE WHEN USING THE SCRIPT ON YOUR OWN SITE Const MAIL_FROM_NAME = "WEBSERVER ERROR HANDLER" 'Name of email sender Const MAIL_FROM_EMAIL = "Website@Rupholdt.com" 'Email address of email sender Const MAIL_TO_NAME = "MR. WEB DEVELOPER" 'Name of email recipient Const MAIL_TO_EMAIL = "Bob@Rupholdt.com" 'Email address of email recipient Const MAIL_SUBJECT = "Webserver Error Report" 'Title of error report Const MAIL_HOST = "smtp.rupholdt.com" 'Address of the host used to send the mail 'Generate the top part of the error report HTML = "" HTML = HTML & "" HTML = HTML & "" HTML = HTML & "" & MAIL_SUBJECT & "" HTML = HTML & "" HTML = HTML & "" HTML = HTML & "

" HTML = HTML & "" & MAIL_SUBJECT & "
" HTML = HTML & "Error Report Generated: " & FormatDateTime(now(), vbLongDate) & ", " & FormatDateTime(now(), vbLongTime) & "
" HTML = HTML & "


" 'Generate the error report general description HTML = HTML & "Details:
" HTML = HTML & "Error In Page: " & Request.ServerVariables("PATH_INFO") & "
" HTML = HTML & "Error Type: " & ErrorType & "
" HTML = HTML & "Error Source: " & ErrorSource & "
" HTML = HTML & "Error Number: " & ErrorNumber & "
" HTML = HTML & "Error Description: " & ErrorDescription & "
" HTML = HTML & "
" 'Report the contents of the QueryString collection HTML = HTML & "QueryString Collection:
" If QS.Count > 0 Then For Each CollectionItem In QS HTML = HTML & CollectionItem & " : " & QS(CollectionItem) & "
" Next Else HTML = HTML & "The QueryString collection is empty
" End If HTML = HTML & "
" 'Report the contents of the Form collection HTML = HTML & "Form Collection:
" If RF.Count > 0 Then For Each CollectionItem In RF HTML = HTML & CollectionItem & " : " & RF(CollectionItem) & "
" Next Else HTML = HTML & "The Form collection is empty
" End If HTML = HTML & "
" 'Report the Server object properties HTML = HTML & "Server Settings:
" HTML = HTML & "ScriptTimeout: " & Server.ScriptTimeout & "
" HTML = HTML & "
" 'Report the Session object properties and the contents of the Session collection 'IMPORTANT: If you have disabled Sessions either in IIS or 'by use of the @ENABLESESSIONSTATE = FALSE directive then you MUST comment out this section HTML = HTML & "Session Settings:
" HTML = HTML & "CodePage: " & Session.CodePage & "
" HTML = HTML & "LCID: " & Session.LCID & "
" HTML = HTML & "SessionID: " & Session.SessionID & "
" HTML = HTML & "Timeout: " & Session.TimeOut & "
" HTML = HTML & "
" HTML = HTML & "Session Collection:
" For iNumber = 1 To Session.Contents.Count If IsObject(Session.Contents(iNumber)) Then HTML = HTML & Session.Contents.Key(iNumber) & "[Object]
" Else If IsArray(Session.Contents(iNumber)) Then HTML = HTML & Session.Contents.Key(iNumber) & "[Array]
" Else HTML = HTML & Session.Contents.Key(iNumber) & ": " & Session.Contents(iNumber) & "
" End If End If Next HTML = HTML & "
" 'Report the contents of the Application collection HTML = HTML & "Application Collection:
" For iNumber = 1 To Application.Contents.Count If IsObject(Application.Contents(iNumber)) Then HTML = HTML & Application.Contents.Key(iNumber) & "[Object]
" Else If IsArray(Application.Contents(iNumber)) Then HTML = HTML & Application.contents.Key(iNumber) & "[Array]
" Else HTML = HTML & Application.contents.Key(iNumber) & ": " & Application.Contents(iNumber) & "
" End If End If Next HTML = HTML & "
" 'Report the contents of the Server Variables collection HTML = HTML & "Server Variables:
" For Each CollectionItem in request.servervariables If CollectionItem <> "ALL_HTTP" and CollectionItem <> "ALL_RAW" then HTML = HTML & CollectionItem & " : " & request.servervariables(CollectionItem) & "
" End If Next HTML = HTML & "" HTML = HTML & "" 'Send the error report using email. This currently uses ASPMail from serverobjects.com, but could be 'adapted to use another mail sending object (e.g. CDONTS) if required 'Set myMail = Server.CreateObject("SMTPsvg.Mailer") 'myMail.RemoteHost = MAIL_HOST 'myMail.FromName = MAIL_FROM_NAME 'myMail.FromAddress = MAIL_FROM_EMAIL 'myMail.AddRecipient MAIL_TO_NAME, MAIL_TO_EMAIL 'myMail.Subject = MAIL_SUBJECT 'myMail.BodyText = HTML 'myMail.ContentType = "text/html" 'Send the error report using email. This currently uses CDONTS, but could be 'adapted to use another mail sending object if required Set myMail = CreateObject("CDONTS.NewMail") With myMail .From = MAIL_FROM_NAME & "<" & MAIL_FROM_EMAIL & ">" .To = MAIL_TO_NAME & "<" & MAIL_TO_EMAIL & ">" .Subject = MAIL_SUBJECT .Value("MIME-Version") = "1.1" .BodyFormat=0 .MailFormat=0 .Body=HTML .Send End With Set myMail = Nothing End Function %>