English
 电子信箱
 加入收藏

  威盾防火墙 >> 支持与下载 >> 技术文章 >> ASP中的错误代码技巧

 

ASP中的错误代码技巧

威盾防火墙 2007-03-23

 
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 see 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 see 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
%>
<html>
<head>
<title>Records been added</title>
</head>

<body>

<p>Your record has been added to the database!</p>
</body>
</html>

Standard Error coding page I use in most all my apps! You also could easily create some kind of database
connection and report the errors your getting!

<%@ language="vbscript"%>
<%
'buffers the page on the server
Response.Buffer = True

'Declare variables
dim strNumber
dim strdesc
dim conn
dim rs

'sets a local variable to the connection string
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("error.mdb")

'Place values that are in the URL into local variables
strNumber = request("Number")
strDesc = request("Desc")

'Opens the connection string and recordset object to record the error in a database
set conn = server.createobject("adodb.connection")
conn.open strconn
set rs = server.createobject("adodb.recordset")
rs.open "tblError", conn, 2, 2
rs.addnew
rs("ErrNumber") = strNumber
rs("ErrDesc") = strDesc
rs("timeoccurred") = now()
rs.update
rs.movelast

'Puts the generated ID into a local variable
strID = rs("id")
rs.close
set rs = nothing
conn.close
set conn = nothing

'Clear errors collections
err.clear

%> </p>

<html>
<head>
<title>Error page</title>
</head>
<body>

<h1>An Error has occurred</h1>
'Writes out the generated Number that is received from the database
'Idea you also could format an email message with this id to report the error to someone
<h2>Error ID is:<% = strID %></h2>

<h3>The Error Number is:</h3>
<i><% = strNumber %>
</i>

<h3>The Error Description is:</h3>
<i><% = strDesc %>
</i>

<h3>Please report this error to the webmaster</h3>
<b><a href="[email protected]">

<p>Click here to send an email please report the Error Number and Description</a></b> </p>
</body>
</html>


相关内容: 最新内容:
利用ASP远程注册DLL的方法[2007-03-23]
用sql语句访问access和mssqlserver数据库[2007-03-23]
如何解决用Access数据库建站维护不便的问题[2007-03-23]
MD5 算法的ASP实现[2007-03-23]
ASP比较两个日期的相差天数[2007-03-23]
ASP中怎么实现SQL数据库备份、恢复[2007-03-23]