PRB: Values Not Stored Correctly in a Multiuser Environment

Last reviewed: April 29, 1996
Article ID: Q98699
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for Windows, versions 2.5 and 2.5a
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a

SYMPTOMS

In a multiuser environment, programs that assign values to memory variables from database fields may not have access to the most recent values of those database fields.

CAUSE

To reproduce this problem, create a database with a numeric field, named FIELD1, and one record. Assign an initial value of 1 to FIELD1. Start the following program on one workstation:

   SET EXCLUSIVE OFF
   SET TALK OFF
   USE <database>
   DO WHILE .T.
     m.memvar = field1
     WAIT WINDOW NOWAIT "Current value of FIELD1 is: " + ;
       LTRIM(STR(m.memvar))
   ENDDO

Start the following program on a second workstation:

   SET EXCLUSIVE OFF
   SET TALK OFF
   USE <database>

   FOR i = 1 TO 2000
     REPLACE field1 WITH i
     WAIT WINDOW NOWAIT "Current value of FIELD1 is: " + ;
        LTRIM(STR(i))
   ENDFOR

Changes in the value of FIELD1 should be reflected in the first workstation's display; however, the displayed value of FIELD1 never changes.

NOTE: Unless an RLOCK() function is issued, FoxPro does not re-read the current record.

RESOLUTION

For memory variables to be assigned the most current information from a database record, an RLOCK() function should be issued before performing the assignment. In the code example above, the first workstation's code should be modified to read:

   SET EXCLUSIVE OFF
   SET TALK OFF
   SET REPROCESS TO <an appropriate interval>
   USE <database>
   DO WHILE .T.
     IF RLOCK()
       UNLOCK
       m.memvar = field1
       WAIT WINDOW NOWAIT "Current value of FIELD1 is: " + ;
         LTRIM(STR(m.memvar))
     ENDIF
   ENDDO

The second workstation's code should be modified to read as follows:

   SET EXCLUSIVE OFF
   SET TALK OFF
   SET REPROCESS TO <an appropriate interval>
   USE <database>

   FOR i = 1 TO 2000
     IF RLOCK()
       REPLACE field1 WITH i
       UNLOCK
       WAIT WINDOW NOWAIT "Current value of FIELD1 is: " + ;
         LTRIM(STR(i))
     ENDIF
   ENDFOR


Additional reference words: VFoxWin 3.00 FoxDos FoxWin 2.00 2.50 2.50a
multi-user
KBCategory: kbprg kbprb
KBSubcategory: FxprgMultiuser


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.