Microsoft KB Archive/195837

= PRB: Error Returned When Attempting to Modify JET Database =

Article ID: 195837

Article Last Modified on 1/8/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q195837



SYMPTOMS
When attempting to modify a JET database, the following error is returned:

"Run-time error '3211': The database engine couldn't lock table '' because it's already in use by another person or process.".



CAUSE
Attempting to create a relation that involves a table that is currently open can cause this error.



RESOLUTION
The best workaround is to close the recordset that contains the table being used in the relation.



STATUS
This behavior is by design.



MORE INFORMATION
The following example will open a database (use Nwind.MDB), open a table within that database, and then attempt to create a relation using the open table.

Steps to Reproduce Behavior
 Create a Standard EXE project in Visual Basic. Form1 is created by default. Under Project/References, add "Microsoft DAO 3.51 Object Library."  Add a CommandButton to Form1 and add the following code under the Click event: Dim Fld as Field Dim Tbl as Recordset Dim Rel as Relation Dim db as Database

Set db = OpenDatabase("nwind.mdb", True)

Set Tbl = db.OpenRecordset("employees", dbOpenTable) ' Note that employees table is used below in creating the relation. ' Uncommenting the line below allows the code to work properly. ' Tbl.Close

Set Rel = db.CreateRelation("myrel") Rel.Table = "Employees" Rel.ForeignTable = "Orders" Set Fld = Rel.CreateField("EmployeeID") Fld.ForeignName = "EmployeeId" Rel.Fields.Append Fld

' eError will occur on next line. db.Relations.Append Rel

 Uncomment the line for closing the recordset and note the relation is created and added to the database without error.</ol>

Keywords: kberrmsg kbprb KB195837

-

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

© Microsoft Corporation. All rights reserved.