Click here to Skip to main content
13,194,662 members (51,155 online)
Click here to Skip to main content
Add your own
alternative version


33 bookmarked
Posted 24 Apr 2002

Trap ASP and SQL errors in your site

, 25 Apr 2002
Rate this:
Please Sign up or sign in to vote.
Trap the ASP and SQL errors in your Site


This article shows you how to trap the ASP & SQL errors in your site.

First thing to do is to change the Custom Error for The Web Site Properties
[Internal Server Error] - HTTP Error 500 & 500;5001 to this URL -> /trap.asp 

Now create the trap.asp file using the code shown below.

Code Listing

Const lngMaxFormBytes = 200

Response.Buffer = true

If Response.Buffer Then
    Response.Status = "500 Internal Server Error"
    Response.ContentType = "text/html"
    Response.Expires = 0
End If

Set objASPError = Server.GetLastError

strServername     = LCase(Request.ServerVariables("SERVER_NAME"))
strServerIP     = Request.ServerVariables("LOCAL_ADDR")
strRemoteIP     = Request.ServerVariables("REMOTE_ADDR")
strCategory     = objASPError.Category
strASPCode     = Server.htmlEncode(objASPError.ASPCode)
intNumber     = objASPError.Number
strFile         = objASPError.File
intLine         = objASPError.Line
intColumn     = objASPError.Column
strSource     = server.htmlEncode(objASPError.Source)
strDescription     = Replace(Server.htmlEncode( _
strASPDescription= Replace(Server.htmlEncode( _

Response.Write "Sorry, but the site is not available."

You could send the email to the webmaster, with the error.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Fernando Finelli
Web Developer
Argentina Argentina
Lic. Fernando Finelli

You may also be interested in...


Comments and Discussions

QuestionHow it go to error section in asp error trap Pin 18:16 18:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171018.2 | Last Updated 26 Apr 2002
Article Copyright 2002 by Fernando Finelli
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid