Error just finished your ASP application in time, barely making the dealine! As you upload the final version of the webserver, you receive an email from your supervisor indicating so he's ready for Your demo. You confidently stride to his office and give him instructions on accesses the application the Intranet.
Your boss comes to the "the" the "the" the "the", "is asked" to "enter his name. You have ' ve created a slick, customized feel to the site, recording the user and he or her preferences in a database. Your boss types in his name, "The pointy haired Boss," and hits the Submit button. Instead of being taken to the next page, and he sees the following text pops up on the screen:
Microsoft OLE DB Provider for ODBC Drivers error ' 80004005 ' [microsoft][odbc Access ODBC driver Driver] syntax wrong n Ear '
Please do I just made this error message up, so, please, no emails asking about how one gets this error by entering His name!
You get one of the those looks from your bosses, a look at that says, "I hope you weren ' t expecting a positive performance."
There ' s nothing worse to a end user than to the those dreaded ADO errors. They are misformatted, cryptic, and leave the user wondering what the They are to do. Your average end user doesn ' t know ODBC from OLE. So can you prevent these nasty error messages?
Must insert at the top of your ASP page:
<% on Error Resume Next%>
This would tell the ASP to just skip the any errors, instead of halting execution and printing the error message. You are tempted to leave it in this, although if you did, and errors occur, your users won ' t be aware of them. They'll their information is correctly saved, when in the actuality it wasn ' t due to a ADO error.
What, then, do we want to do if there are an error? So, the idea situation would is to let the "end user Know" An error had occurred and would be worked on, and automatic Ally email technical Support with the ADO error messages. So this is what we do!
The question now are how do we "trap" errors? So, after no ADO call that accesses the database, we'll want to put the following lines:
If Err.Number <> 0 Then
Traperror Err.Description
End If
You'll want to put this is the communicate directly with the database in all ADO calls. This includes Connectionobject.open, Connectionobject.execute, and Recordsetobject.open. Now, you are wondering where the sub traperror is Defined:we ' re about to doing that. Create a file called errorhandler.asp and put it in Your/include or/scripts directory. In errorhandler.asp, we'll have the following subs:
Traperror
Processerrors
Let's look in the code for errorhandler.asp:
<%
Dim Strerrormessage
Dim bolerrors
' Initialize variables
Strerrormessage = "" ' The error messages for tech. Support
bolerrors = False ' Have We found any errors yet?
' Now we two subs
Sub Traperror (strerror)
bolerrors = True ' Egad, we ' ve found an error!
Strerrormessage = strerrormessage & strerror & ","
End Sub
' If there are any errors, this function would email tech. Support
Sub Processerrors ()
If Bolerrors Then
' Send the email
Dim OBJCDO
Set OBJCDO = Server.CreateObject ("CDONTS. NewMail ")
objcdo.to = "Techsupport@mysite.com"
Objcdo.from = "Techsupport@mysite.com"
Objcdo.subject = "An ADO ERROR occurred"
Objcdo.body = ' at ' & Now & ' The following errors occurred on ' & _
"The page" & Request.ServerVariables ("Script_name") & _
":" & _
Chr (a) & Chr (a) & Strerrormessage
Objcdo.send
Set Objcdo = Nothing
' Now, we ' ve got to print out something for the user
Response.Write "There has been a database error. Technical Support "& _