SYMPTOMS
In a multiuser situation in Microsoft Visual FoxPro, when you perform tasks that affect the contents
of a database (.DBC file), you receive the following error message:
The database must be opened exclusively.
WORKAROUND
If you receive the error "The database must be opened exclusively" at
design time, all developers must close the database before you can proceed.
To prevent this error from occurring at run time when manipulating views or
connections, create a local database for each user. All users will have
exclusive access to their database, and will also be able to update the
table records contained in a centralized, shared database.
To verify whether or not a database is open exclusively, use the
ISEXCLUSIVE() function. The syntax for the ISEXCLUSIVE() function is:
ISEXCLUSIVE([cTableAlias | nWorkArea | cDatabaseName [, nType]])
When the nType parameter has a value of 2, the function returns the
exclusive status for a database. The following example code makes sure the
database is open exclusively before using the INDEX ON command:
CLOSE ALL
OPEN DATABASE SYS(2004)+"SAMPLES\DATA\TESTDATA"
SELECT 0
USE CUSTOMER
IF ISEXCLUSIVE('testdata',2)
INDEX ON CITY TAG CITY
ELSE
=MESSAGEBOX("Database must be opened Exclusively")
ENDIF
CLOSE DATABASE
NOTE: The above code uses CLOSE ALL to close all the files so that the
database can be opened but not selected, making the CLOSE DATABASE command
useless. Of course using CLOSE DATABASE ALL might not be helpful if only
one database needs to be closed. Therefore, issue the following code to
select a certain database to close and reopen:
SET DATABASE TO <dbc name>
CLOSE DATABASE
OPEN DATABASE <dbc name> EXCLUSIVE
This ensures that the correct database container is selected, closed, and
reopened.