| xHarbour Reference Documentation > Command Reference |
![]() |
![]() |
![]() |
Opens a database and its associated files in a work area.
USE [<cDatabase> ;
[INDEX <cIndexFiles,...>] ;
[ALIAS <cAlias>] ;
[EXCLUSIVE | SHARED] ;
[NEW] ;
[READONLY] ;
[VIA <cRDD>] ;
[CODEPAGE <cCodePage>] ;
[CONNECTION <nConnection>]]
If no argument is specified, all files open in the current work area are closed.
The USE command opens a database file along with its associated memo files in the current work area. Optionally, index files belonging to the database can be opened as well. Only one database can be open at any time in one work area. The maximum number of work areas is 65535.
USE operates in the current work area, which can be selected using the SELECT command. As an alternative, the NEW option of USE selects the next free work area as current and then opens the file. When the database is open, its record pointer is positioned on the first logical record, if indexes are opened, or on record number 1.
Index files can be opened along with the database using the INDEX option. It is, however, recommended to open first the database file alone, check the success of file opening with NetErr() and then open associated index files in a separate operation using SET INDEX.
File access to the database in a multi-user environment is controlled with the options SHARED and EXCLUSIVE. Shared file access requires record locking for updating records during database operations. This is accomplished with function RLock().
| See also: | CLOSE, DbSetIndex(), DbUseArea(), NetErr(), OrdListAdd(), RddSetDefault(), SELECT, SET DEFAULT, SET INDEX, SET PATH, Used() |
| Category: | Database commands |
| Source: | rdd\dbcmd.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example demonstrates the recommended procedure of opening a databse
// and its indexes in a multi-user environment:
PROCEDURE Main
USE Customer SHARED NEW
IF .NOT. NetErr()
SET INDEX TO Cust01, Cust02, Cust03
ELSE
? "Unable to open database"
BREAK
ENDIF
<database operations>
CLOSE ALL
RETURN
http://www.xHarbour.com