Microsoft KB Archive/153018

= BUG: CreateDynaset Holds Lock on Index if No Records Return =

Article ID: 153018

Article Last Modified on 3/2/2005

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q153018



SYMPTOMS
After opening a Dynaset that contains no records with a SQL statement that refers to an indexed field, attempting to access that table from another application can cause the following error:

Couldn't save; currently locked by  on machine 

To work around this problem, add a call to the Idle method of the DBEngine object immediately after the call to OpenRecordset. Add the following line of code: DBEngine.Idle dbFreeLocks



CAUSE
The error occurs because the Jet engine is not, by default, releasing the lock on the index page after opening the Recordset. This behavior only occurs when the Recordset returned contains no records. It occurs with Jet 2.5 and Jet 3.0, but doesn't occur with Jet 1.1.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



Steps To Reproduce Problem
 Start Visual Basic 4.0. Form1 is created by default. Open the References dialog (Tools Reference), and add a reference to either DAO 2.5 (16-bit) or DAO 3.0 (32-bit). Add a single Command button to Form1.  Add the following code to the form: Private Sub Command1_Click Set db = OpenDatabase("BIBLIO.MDB") Set rs = db.OpenRecordset("Select * From Authors Where AU_ID > _              200", dbOpenDynaset) End Sub  From the Insert menu, choose Module, and insert a single code module.</li>  Add the following code to the module: Global rs As Recordset Global db As Database </li> Press the F5 key or select Start from the Run menu to run the application. Click on the Command button to open the database, and create a Recordset.</li> Start another instance of Visual Basic. From the Add-Ins menu, choose Data Manager, and start the Data Manager application.</li> In Data Manager, open the same BIBLIO database that was opened in step 4. Open the Authors table and attempt to add a new record. When the update is attempted, Data Manager will give the error mentioned above.</li></ol>

Keywords: kbbug kbdatabase kbpending KB153018

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.