Recommended: Several common mistakes made by ASP beginners Several common mistakes made by ASP beginners 1. Open again before the record set is closed:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Taking the most popular ASP in China as an example, I don’t know how many people think of the concept of fault tolerance when writing code. In fact, when I encounter such a thing, it is left unresolved. Why? Think about it, the original meaning was that you could tolerate mistakes by writing the following code, see Example 1-1.<%@ Language=VBScript %>
<%option explicit%>
<%
'Missage filtering
on error resume next
…………………(Code omitted)
%>
Example 1-1 A glimpse of common codes
The above code often appears in the hands of all colleagues. Needless to say, I can understand your current mood after completing it. I can tell you frankly that most of the ASP web pages I have written for two years are in this way, constantly writing, constantly modifying, and exhausted, and now I am unwilling to turn back and rewriting my own code. In fact, the most basic idea of fault tolerance mechanism is not to believe that the program can save you much, but to take control in your own hands. This is necessary.
<%@ Language=VBScript %>
<%Option Explicit%>
<%
'======================================================
DIM NDEBUG_MSG
NDEBUG_MSG=TRUE
IF NDEBUG_MSG = TRUE THEN
'Missage filtering
ON ERROR RESUME NEXT
END IF
'=====================END =========================
…………………(Code omitted)
'Data transaction processing-start
If Err.number = 0 Then
'~~~~~ Open database and begin transaction ~~~~~~~~~~~~~~~~~~~~~~~~~~
'------------------------------
'-------------------------------------
objConn.BeginTrans
objConn.Execute (objSQL)
'~~~~~~ Commit the transaction and close the database connection
objConn.CommitTrans
Response.CacheControl =Private
Response.Expires = -1
…………………(Code omitted)
Else
'~~~~~~ Rollback transactions and close objects
objConn.RollbackTrans
'~~~~~ Raise errors for asp page
'Err.Raise Err.Number, Err.Source, Err.Description
'Err.Clear
Response.Write Description= (& err.number &),(& err.Description &)
End If
'=====================END FILES==========================
%>
Example 1-2 Complete error tolerance mechanism code example
After reading the above code, you will find that there are no superb skills in it, and experts may even look down on it. But you may not be able to do this when writing code.
Share: asp instance: Testing WEB server The following is the quoted content: <HTML><HEAD><TITLE>Test the WEB server</TITLE></HEAD><BODY><Script l