
Database locked in a multiuser environment
Quote:
> If I use the following code in a multiuser environment, the database gets
> locked up and no
> records are added to the database anymore. The error I get is 'could not
> save, database locked by
> user xxx". If I trace the error as you can see in my code, the routine
> finaly exits without
> adding a record.
> What do I do wrong and how do I solve this?
> Sub MakeLog(D$, T$, Program$, Level As Integer, StudentID As Long, LessonID
> As Long, Computer$, Comments$)
> Dim Try As Integer
> Dim Tijd As Long
> Try = 0
> On Error GoTo CouldNotUpdate
> Dim MyDb As Database, MyDn As Dynaset, MyFd As Field
> Set MyDb = OpenDatabase(DBaseName, False, False)
> Set MyDn = MyDb.CreateDynaset("Log", DB_APPENDONLY)
> MyDn.AddNew
> MyDn.Fields("Date") = D$
> MyDn.Fields("Time") = T$
> MyDn.Fields("Program") = Program$
> MyDn.Fields("Level") = Level
> MyDn.Fields("StudentID") = StudentID
> MyDn.Fields("LessonID") = LessonID
> MyDn.Fields("Computer") = Computer$
> MyDn.Fields("Comments") = Comments$
> MyDn.Update
> MyDn.Close
> MyDb.Close
> Exit Sub
> CouldNotUpdate:
> Try = Try + 1
> If Try > MAXTRY Then Exit Sub
> Tijd = Timer + (5 * Rnd)
> While Timer - Tijd < 0
> Wend
> Resume
> End Sub
> +---------------------------------------------------------------+
> | Drs P.M. Bloemendaal |
> | Dept. of Surgery, University Hospital Leiden, The Netherlands |
> | fidonet : 2:281/908.0 |
> +---------------------------------------------------------------+
You might try changing the OpenDatabase statement to thus:
Set MyDb = OpenDatabase(DBaseName, True, False)
The second argument determines whether the database is opened
for exclusive use. You need exclusive use for updates. This prevents
others from opening the database until your update is completed, thereby
preventing deadlocks. If you're just going to read, you might use this:
Set MyDb = OpenDatabase(DBaseName, False, True)
The third argument determines whether the database is opened
as read only. This cuts down on some processing overhead and may
speed up your queries. Setting the second argument to false, for
non-exclusive use, allows others to open the database for reading
as well.
Cordially,
Bob Moss