Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
ASP's Database Classes
First, the preface
Referring to ASP operation database, most people would think: Common connection string constr, Conn.Open constr Establish database connection, Conn.execute sqlcmd Execution Command, Recordset.Open Sql,conn, 1,1 get a Recordset, it is true that this method is adopted by 99% of people or companies. For errors that occur during the operation of the database, it is feared that 99% of the people will not process it, either by adding on Error Resume Next "easily" at the beginning of the program, or by having the error message "corpse" with the error code in front of the viewer. The first situation can be a strange and bizarre result, the latter case, may be at a certain time (such as connecting to the database) to expose your sensitive information, affecting the security of the site. Of course, there are individual responsible programmers who will add an if err.xxxx to handle possible errors after an error-prone operation, but this does not seem to be a good idea, inadvertently may be omitted.
I still do not want to understand, why in VB and asp.net exist in the Error Goto, but in the ASP was canceled.
Also have to mention is that when you use On Error Resume Next and do not want to resume next in the back, sorry, no way, you can only "carry it out". Look at the exception mechanisms in other languages, try ... Catch.. Finally arbitrary, really cool!
Say so much, and do not introduce new content such as exception mechanism for ASP, after all, the ASP language itself also determines that this is not possible (implemented in asp.net), just want in the ASP is the most common and most prone to error in the database operations, find an effective way to deal with the error, and the Conn , the recordset and so on encapsulation, achieves the maximum simplification. So we have the following database class.
Second, the database class
As mentioned earlier, the purpose of this class is to encapsulate the tedious operations of Adodb.connection and Adodb.recordset and to implement error handling in the class. Now look at the members, properties, and methods of the class:
1) Members: (no public or protected members)
classname-Return class name
lasterror-returns the last error
ignoreerror-Sets/Returns whether database errors are ignored
connection-return Connection object (adodb.connection)
connectionstring-Set/Return connection string (this example is SQL Server, as for other please according to the actual setting)
FieldCount, PageSize, PageCount, AbsolutePage, AbsolutePosition, Bof, eof-, please refer to adodb.recordset appropriate content
setup-set up the account number, password, database name, host/IP connection data server
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.