Database locked in a multiuser environment 
Author Message
 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
>     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

Looks pretty good except, place your addnew and update within a transaction;
that actual update will go faster.  You might also increase the number of
retrys.

Personally, I would also forgo the dynaset and go with the table object. You
can buy a little more speed by not having to create the dynaset.

Frank....

--



Sun, 30 Aug 1998 03:00:00 GMT  
 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



Sun, 30 Aug 1998 03:00:00 GMT  
 Database locked in a multiuser environment


Quote:
>    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:

What exactly do you mean with deadlocks? And if I open the database
exclusive, other tables can not be updated anymore.

-=Peter=-

+---------------------------------------------------------------+
| Drs P.M. Bloemendaal                                          |
| Dept. of Surgery, University Hospital Leiden, The Netherlands |

|       fidonet : 2:281/908.0                                   |
+---------------------------------------------------------------+



Tue, 01 Sep 1998 03:00:00 GMT  
 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

>>     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

The 2kbyte page level locking in Access 1-7 is a real pain. Perhaps the next version will have row level locking. My strategy is illustrated below. If there is a conflict we put up a message to that effect and in the time it takes the user to read it and respond the lock has usually been released. It is far from a perfect solution but better that padding out each row to 2kbytes. Any other ideas?

Public Function PersistPolicyUsing(coverId As Long, renewedCert As Long)
Dim Insurance As Recordset, DB As Database

On Error GoTo RecoverCert:

    Set DB = OpenDatabase(DatabaseName)
    Set Insurance = DB.OpenRecordset("InsuranceContract", dbOpenTable)

    Insurance.LockEdits = False
    Insurance.AddNew
    Insurance("PolicyNumberForeignKey") = CurrentCertificateNumber
    Insurance("CoverageForeignKey") = coverId
    Insurance("CertificateNumberIssuedDate") = Now
    Insurance("CertificateNumberIssuedBy") = BuildBase.User
    Insurance("AmountCharged") = modifyAmountCharged
    Insurance("AmountCalculated") = AmountCalculated
    Insurance("DiscrepancyReason") = DiscrepancyReason
    Insurance("Gross") = AmountCharged
    Insurance("RenewedCertificateNumber") = renewedCert
    Insurance.Update

    Exit Function

RecoverCert:

    MsgBox Error$
    If Err > 3000 Then
        MsgBox BUSY_TABLE
        Resume
    Else
        Exit Function
    End If

End Function



Tue, 01 Sep 1998 03:00:00 GMT  
 Database locked in a multiuser environment

Quote:



> >    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:

> What exactly do you mean with deadlocks? And if I open the database
> exclusive, other tables can not be updated anymore.

> -=Peter=-

> +---------------------------------------------------------------+
> | Drs P.M. Bloemendaal                                          |
> | Dept. of Surgery, University Hospital Leiden, The Netherlands |

> |       fidonet : 2:281/908.0                                   |
> +---------------------------------------------------------------+

    A deadlock occurs when two or more database users attempt to
apply an update simultaneously and are caught in a situation where
one is waiting for the other to finish their update before completing
their own.  This can happen with databases opened with non-exclusive
access.

    It is true that if you open a database with exclusive access
that other processes will not be able to open any tables within the
database.  The best approach for update processes is to open the
database with exclusive access only for the duration of the update
process.  In other words, open the database, complete the update,
and immediately close the database all in the same process.  Do not
leave the database open with exclusive access any longer than
necessary.  For batches of updates you should consider using
transaction processing as well.

    Cordially,
    Bob Moss



Tue, 01 Sep 1998 03:00:00 GMT  
 Database locked in a multiuser environment

Quote:

>The 2kbyte page level locking in Access 1-7 is a real pain. Perhaps the next
> version will have row level locking. My strategy is illustrated below. If
> there is a conflict we put up a message to that effect and in the time it
> takes the user to read it and respond the lock has usually been released. It
> is far from a perfect solution but better that padding out each row to
> 2kbytes. Any other ideas?

One of the problems that I've Noticed on busy systems is that the DBEngine
Doesn't seem to release the 2K lock for a few seconds, especially if you
immediately pop into another task.

you can also try forcing the DbEngine to Clear The Locks by forcing the IDLE
method on the Engine like This:

        DbEngine.Idle   DbFreeLocks

This will force the DbEngine to Think it has some free time to clean up any
outstanding Page locks that it might have sitting around.

-Scott Singleton



Fri, 04 Sep 1998 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Additional Record Locking alert for multiuser environment

2. Tables locked in multiuser environment

3. Locking problems in multiuser environment

4. Record Locking in a multiuser environment

5. Access 2000 lock errors in multiuser environment

6. Multiuser Environment - File/Record locks

7. Multiuser Environment - File/Record locks

8. Locking Record in Multiuser Database

9. RECORDSET problem in multiuser environment

10. trouble modifying in multiuser environment

11. Repair AccessDB in Multiusers environment

12. Updating Records in a Multiuser Environment

 

 
Powered by phpBB® Forum Software