Article ID: 252317 - Last Review: August 5, 2004 - Revision: 3.2 SAMPLE: Rowlock.exe Demonstrates Row-Level Locking Using ADO & SQL ServerThis article was previously published under Q252317 On This PageSUMMARY RowLock.exe is a sample file that demonstrates how to use
Microsoft ActiveX Data Objects (ADO) with Microsoft SQL Server in a Microsoft
Visual Basic application to lock individual rows within a recordset while they
are being changed. MORE INFORMATIONThe
following file is available for download from the Microsoft Download
Center: RowLock.exe
(http://download.microsoft.com/download/ado/utility/2.5/win98/en-us/rowlock.exe)
Release Date:
May-17-2000For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base: 119591
(http://support.microsoft.com/kb/119591/EN-US/
)
How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most
current virus-detection software that was available on the date that the file
was posted. The file is stored on security-enhanced servers that help to
prevent any unauthorized changes to the file.
The sample opens a recordset from the pubs database and
allows the user to browse the records. The user can then update any of the
fields if required. If a second client connects, they can browse the recordset
and edit any of the records apart from the one being edited by the first
client. If both clients try to edit the same record, a message box with this
error message displays: Row locked by another user.
Note Pressing any navigation button during a transaction will rollback any changes. Run two instances of the sample and browse the recordset by using both clients. Browse to a record and begin a transaction with the first client. Now, try to begin a transaction on the same record with the second client. A message box appears, which states that the row is currently locked. Browse to a different record with the second client, begin a transaction, make some changes and then either rollback or commit the changes. Rollback or commit the changes on the first client. The sample works by opening an optimistic server-side cursor on the recordset. This allows free browsing of the recordset. When the user begins editing (starts a transaction), a pessimistic cursor opens on the recordset at the appropriate record, locking only that record. A rollback or commit selection releases the lock and opens an optimistic cursor again. Notes
APPLIES TO
| Article Translations
|

Back to the top
