Recordset method of ASP record set object

Source: Internet
Author: User
Tags dsn

The day before yesterday, the customer found the following problem: Database (SQL Server 2000) andProgram(ASP) is copied from another host, but the system is not logged on, prompting that the user password is incorrect. At the beginning, the user thought it was a database or program configuration problem. However, after searching for the database for a long time, the user did not find any problems.CodeNow, I didn't think it was a problem with the code. Because the code is completely copied from another machine, there should be no problem. There is no way to enable code debugging. I found the error occurred when opening the data record. ------ "some attributes and methods are not supported." I found the problem.

When data was originally opened:
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "DSN = mydb; uid = myuser; Pwd = mypass"
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * from user"
Rs. Open SQL, Conn, 1, 1
Then changed:
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "DSN = mydb; uid = myuser; Pwd = mypass"
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * from user"
Rs. Open SQL, Conn, 3, 3

You can log on to the system. After the problem was solved, the problem occurred because the code was not written by me, so I did not take a closer look (there was no time at the time. Paste the following attributes and methods related to recordse in ASP:

Recordset Method
 
Rs. movenext moves the record pointer down a row from the current position
Rs. moveprevious transfers the record pointer from the current position to a row up
Rs. movefirst move the record pointer to the first row of the data table
Rs. movelast moves the record pointer to the last row of the data table
Rs. absoluteposition = n move the record pointer to the nth row of the data table
Rs. absolutepage = n move the record pointer to the first row of page n
Rs. pagesize = N set N records per page
Rs. pagecount the total number of pages returned Based on pagesize settings
Rs. recordcount total number of returned records
Rs. bof indicates whether the record pointer exceeds the first end of the data table. True indicates yes, and false indicates no.
Rs. EOF indicates whether the returned record pointer exceeds the end Of the data table. True indicates yes, and false indicates no.
Rs. Delete deletes the current record, but the record pointer does not move down
Rs. addnew add record to end of data table
Rs. Update update data table records
--------------------------------------------------------------
Recordset object Method
Open Method
Recordset. Open source, activeconnection, cursortype, locktype, options
Source
The recordset object can be connected to the command object through the source attribute. The source parameter can be a command object name, an SQL command, a specified data table name, or a stored procedure. If this parameter is omitted, the system uses the source attribute of the recordset object.

Activeconnection
The recordset object can be connected to the connection object through the activeconnection attribute. Activeconnection can be a connection object or a string containing the database connection information (connectionstring.

Cursortype
The cursortype parameter of the open method of the recordset object indicates the type of cursor to start data, including adopenforwardonly, adopenkeyset, adopendynamic, and adopenstatic, which are described as follows:
--------------------------------------------------------------
Constant Value description
--------------------------------------------------------------
The default value of adopenforwardonly 0 is to start a forward-only cursor (forward only ). Read-only, and the current data record can only be moved down
Adopenkeyset 1 starts a keyset type cursor. Read-only, the current data records can be freely moved
Adopendynamic 2 starts a dynamic type cursor. It can be read and written, and the current data records can be moved freely.

Adopenstatic 3 starts a static cursor. It can be read and written, and the current data records can be moved freely. You can see the new records.
--------------------------------------------------------------
The preceding cursor types directly affect all attributes and methods of the recordset object. The following lists the differences between them.
--------------------------------------------------------------
Recordset attribute adopenforwardonly adopenkeyset adopendynamic adopenstatic
--------------------------------------------------------------
Absolutepage does not support read/write.
Absoluteposition does not support read/write.
Activeconnection can be read/written or read/write
Bof read-only
Bookmark does not support read/write.
Cachesize: readable/writable
Cursorlocation: readable/writable
Cursortype can be read/written or read/write
Editmode read-only
EOF read-only
The filter can read and write, and can read and write.
Locktype: readable/writable
Marshaloptions: readable/writable
Maxrecords
Pagecount does not support read-only and read-only
Pagesize: readable/writable
Recordcount does not support read-only and read-only
Source: readable/writable
State read-only
Status read-only
Addnew support
Support for cancelbatch
Supported cancelupdate
Clone is not supported.
Support for close
Support for Delete
Getrows support
Move is not supported.
Supported by movefirst
Supported by movelast
Supported by movenext
Supported by moveprevious
Supported by nextrecordset
Open Support
Requery support
Not supported by Resync
Supports support
Update support
Supported by updatebatch
--------------------------------------------------------------
The nextrecordset method is not applicable to Microsoft Access databases.

Locktype
The locktype parameter of the open method of the recordset object indicates the lock type to be used. If this parameter is ignored, the system uses the locktype attribute of the recordset object as the default value. The locktype parameters include adlockreadonly, adlockprssimistic, adlockoptimistic, and adlockbatchoptimistic, which are described as follows:
-------------------------------------------------------------
Constant Value description
--------------------------------------------------------------
Adlockreadonly 1 is the default value. The recordset object is started in read-only mode and cannot run addnew, update, delete, and other methods. Default lock type. The record set is read-only and cannot be modified.
Adlockprssimistic 2 when the data source is being updated, the system will temporarily lock the actions of other users to maintain data consistency. Pessimistic locking: When a record is modified, the data provider attempts to lock the record to ensure that the record is edited successfully. You only need to edit the record at the beginning, and lock the record immediately.
Adlockoptimistic 3 when the data source is being updated, the system does not lock the actions of other users. Other users can add, delete, and modify data. Optimistic Locking: The record is locked only when an update record is submitted using the update method.
Adlockbatchoptimistic 4 when the data source is being updated, other users must change the cursorlocation attribute to adudeclientbatch to add, delete, and modify the data. Optimistic Locking in batches. Multiple records can be modified. Records are locked only after the updatebatch method is called.

When no record needs to be modified, the read-only record set should be used, so that the provider does not need to perform any detection.
For general use, Optimistic Locking may be the best option, because the record is locked for only a short period of time,
The data is updated during this period. This reduces resource usage.

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.