ASP's Database Classes

Source: Internet
Author: User
Tags error code error handling
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 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, 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
1, function
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)
2) Properties:
classname-Return class name
version-return version
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
3) Method:
setup-set up the account number, password, database name, host/IP connection data server
connect-Connection Database
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: 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.