Error code tips in ASP

Source: Internet
Author: User
Tags error code header html header reset urlencode
Error | Tips when error coding in ASP it ' s not as rich a environment as other environments. I really only reports
That is there was a error with some Numbers and descriptions. There is only a few way ' I ' ve found to
This is the end user of the errors. I ' ve seen numerous ways of doing it but found this way the
Most graceful. Remember you have to explicitly check after everything this might cause an error. The
Main ones I ' ve experiences are database openings and recordset openings & updates. This is the sample
Code I Use to check for errors and then redirect them to the error page and record the error into a
Database.. Note This all I error checking is do before the Error it can redirect the page without getting an error of Heading already written to the client. If the
HTML header has been sent to the client can ' t do a response.redirect command.

Page 1 A sample Active Server page form you would use to submit data


<title>enter some data into the field</title>

<body>

<p>enter some data into the field. This form is no more than representing a
form you would use the real life to submit some data to a ASP page. Note this
Isn ' t going to enter the data into the database but it'll record the "error on" an error page
And then the some information about the Error. </p>

<form method= "POST" action= "error2.asp" Name= "Form1" >
Align= "left" ><table border= "1" width= "<div" height= ">"
<tr>
&LT;TD width= "143" height= "one" >favorite computer</td>
&LT;TD width= "185" height= "one" ><input type= "text" name= "T1" size= "></td>"
</tr>
<tr>
&LT;TD width= "143" height= ">favorite Game: </td>
&LT;TD width= "185" height= "><input type=" text "name=" T2 "size=" ></td>
</tr>
</table>
</div><p>:<input type= "Submit" value= "Submit" Name= "B1" ><input "reset" type= "reset"
Name= "B2" ></p>
</form>
</body>

Page 2 The form that's being submitted to and also generates the error that
Redirects it to the Standard Error page (Which are page 3 in this example)

<%@ language= "VBScript"%>
<%
' Hold the page in memory until Response.Flush command are issued or the Response.Buffer = True

' This forces the page to continue to process even though there is an error.
On Error Resume Next

' Declare all variables
Dim conn
Dim rs
Set conn = Server.CreateObject ("Adodb.connection")
Conn.Open "Example_dsn"

' Standard Error Coding if the database won ' t open an Error number would return something else but zero
' I then capture ' the error number and description and are passed using the QueryString method
' The description is using the ' Server.URLEncode function (' This'll fill any spaces in the
Description with
' The correct HTML code
If err.number <> 0 Then
Response.Redirect "error3.asp?number=" & Err. Number & "&desc=" & Server.URLEncode (Err.Description)
End If
Set rs = Server.CreateObject ("Adodb.recordset")
Rs.Open "TABLENAME" Conn 3 3
' Explicitly checks to "if there is a problem opening the table
If err.number <> 0 Then
Response.Redirect "error3.asp?number=" & Err. Number & "&desc=" & Server.URLEncode (Err.Description)
End If

Rs.addnew
RS ("field1") = Request.Form ("field1")
RS ("field2") = Request.Form ("Field2")
Rs.update

' Explicitly checks to "if there is a problem updating the record
If err.number <> 0 Then
Response.Redirect "error3.asp?number=" & Err. Number & "&desc=" & Server.URLEncode (Err.Description)
End If
Rs.close
Conn.close
Set rs = Nothing
Set conn = Nothing
%>
<title>records been added</title>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.