Locking Recordsets in Microsoft Access 2000

Don't get locked out! Have you ever had trouble knowing what is and isn't locked when working with a Microsoft Access program? VBA offers several alternative locking strategies for the developer, ranging from locking the entire database to locking one record at a time. In addition, VBA lets you control how long data will be locked. This article shows you how.

provided by: 
Originally published at Internet.com


Recordset Locking



Recordset locking locks pages of data found in a recordset. By using recordset locking, you can control when and for how long the data is locked. This is different from locking data through bound forms, which gives you little control over the specifics of the locking process.

When you're traversing through a recordset, editing and updating data, locking occurs regardless of whether you intervene, so you must understand when the locking occurs and whether you need to step in to intercept the default behavior. If you do nothing, a record, or possibly an entire page of records, will be locked each time you begin editing data from your VBA code. This record page is 4096 bytes (4K) and surrounds the record being edited. If an OLE object is found in the record being edited, it isn't locked with the record because it occupies its own space.

Pessimistic Locking



VBA lets you determine when and for how long a page is locked. The default behavior is called pessimistic locking, which means that the record or page is locked when the first field is updated. Listing 1 illustrates this process.

Listing 1 - Utilizing Pessimistic Locking Sub PessimisticLock(strAuthorID As String) Dim cnn As ADODB.Connection Dim rst As ADODB.Recordset Dim strCriteria As String Set cnn = New ADODB.Connection cnn.ConnectionString = " Provider=sqloledb;" & _ "Data Source=(local);Initial Catalog=pubs;uid=sa;pwd=" cnn.Open Set rst = New ADODB.Recordset rst.ActiveConnection = cnn rst.CursorType = adOpenKeyset rst.LockType = adLockPessimistic 'Invoke Pessimistic Locking rst.CursorLocation = adUseServer rst.Open "Select * from Authors Where Au_ID ='" _ & strAuthorID & "'", _ Options:=adCmdText rst!City = "Thousand Oaks" 'Lock occurs here rst.Update 'Lock Released Here End Sub NOTE Not all database providers support all lock types. To determine the functionality available for a particular Recordset object, use the Supports method with adUpdate and adUpdateBatch. Furthermore, the adLockPessimistic setting is not supported when the CursorLocation property is set to adUseClient. Whether the provider does not support the locking type, or the cursor location does not support the locking type, no error results. Instead, the closest available locking type is used...

Read article at Internet.com site
Related Articles
- Email Filtering: The Real Deal
Email is probably the favorite Internet related service for most. It's also the one that causes the most problems, with regard to security. People cannot live without email anymore. Most Internet spam is now delivered by email, and more importantly, most viruses are now spread via email.
- Using DMAIC Methodology to Enhance Information Portals
- URL, URL, Little Do We Know Thee
- Understanding the Microsoft Access Runtime Engine
- Seeing through the hype: Web Services
- Zen and the Art of Breaking Security - Part II
- Encrypting an Access Database
Regional Articles
- Locking Recordsets in Microsoft Access 2000 Alabama
- Locking Recordsets in Microsoft Access 2000 Alaska
- Locking Recordsets in Microsoft Access 2000 Arizona
- Locking Recordsets in Microsoft Access 2000 Arkansas
- Locking Recordsets in Microsoft Access 2000 California
- Locking Recordsets in Microsoft Access 2000 Colorado
- Locking Recordsets in Microsoft Access 2000 Connecticut
- Locking Recordsets in Microsoft Access 2000 DC
- Locking Recordsets in Microsoft Access 2000 Delaware
- Locking Recordsets in Microsoft Access 2000 Florida
- Locking Recordsets in Microsoft Access 2000 Georgia
- Locking Recordsets in Microsoft Access 2000 Hawaii
- Locking Recordsets in Microsoft Access 2000 Idaho
- Locking Recordsets in Microsoft Access 2000 Illinois
- Locking Recordsets in Microsoft Access 2000 Indiana
- Locking Recordsets in Microsoft Access 2000 Iowa
- Locking Recordsets in Microsoft Access 2000 Kansas
- Locking Recordsets in Microsoft Access 2000 Kentucky
- Locking Recordsets in Microsoft Access 2000 Louisiana
- Locking Recordsets in Microsoft Access 2000 Maine
- Locking Recordsets in Microsoft Access 2000 Maryland
- Locking Recordsets in Microsoft Access 2000 Massachusetts
- Locking Recordsets in Microsoft Access 2000 Michigan
- Locking Recordsets in Microsoft Access 2000 Minnesota
- Locking Recordsets in Microsoft Access 2000 Mississippi
- Locking Recordsets in Microsoft Access 2000 Missouri
- Locking Recordsets in Microsoft Access 2000 Montana
- Locking Recordsets in Microsoft Access 2000 Nebraska
- Locking Recordsets in Microsoft Access 2000 Nevada
- Locking Recordsets in Microsoft Access 2000 New Hampshire
- Locking Recordsets in Microsoft Access 2000 New Jersey
- Locking Recordsets in Microsoft Access 2000 New Mexico
- Locking Recordsets in Microsoft Access 2000 New York
- Locking Recordsets in Microsoft Access 2000 North Carolina
- Locking Recordsets in Microsoft Access 2000 North Dakota
- Locking Recordsets in Microsoft Access 2000 Ohio
- Locking Recordsets in Microsoft Access 2000 Oklahoma
- Locking Recordsets in Microsoft Access 2000 Oregon
- Locking Recordsets in Microsoft Access 2000 Pennsylvania
- Locking Recordsets in Microsoft Access 2000 Rhode Island
- Locking Recordsets in Microsoft Access 2000 South Carolina
- Locking Recordsets in Microsoft Access 2000 South Dakota
- Locking Recordsets in Microsoft Access 2000 Tennessee
- Locking Recordsets in Microsoft Access 2000 Texas
- Locking Recordsets in Microsoft Access 2000 Utah
- Locking Recordsets in Microsoft Access 2000 Vermont
- Locking Recordsets in Microsoft Access 2000 Virginia
- Locking Recordsets in Microsoft Access 2000 Washington
- Locking Recordsets in Microsoft Access 2000 West Virginia
- Locking Recordsets in Microsoft Access 2000 Wisconsin
- Locking Recordsets in Microsoft Access 2000 Wyoming
Related Articles
- Email Filtering: The Real Deal
Email is probably the favorite Internet related service for most. It's also the one that causes the most problems, with regard to security. People cannot live without email anymore. Most Internet spam is now delivered by email, and more importantly, most viruses are now spread via email.
- Using DMAIC Methodology to Enhance Information Portals
- URL, URL, Little Do We Know Thee
- Understanding the Microsoft Access Runtime Engine
- Seeing through the hype: Web Services
- Zen and the Art of Breaking Security - Part II
- Encrypting an Access Database

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML