Opening a Database

Before accessing records or properties in a database, you must obtain a handle to the database by calling the CeOpenDatabase function. Specify either the database name or its object identifier. The CeOpenDatabase function returns an open database handle that you can use in subsequent calls for reading or modifying the database. When you finish using the database, close the handle by calling the CloseHandle function.

To increase performance when reading many properties, use the CEDB_AUTOINCREMENT flag when calling CeOpenDatabase. This flag directs the system to automatically increment the seek pointer every time you access a database property with the CeReadRecordProps function. The seek pointer marks the record that will be read by the next read operation.

When calling CeOpenDatabase, you can specify the identifier of a property to use as the sort order for the database. The system uses the sort order to increment the seek pointer after each subsequent call to CeReadRecordProps, if the CEDB_AUTOINCREMENT flag is specified. The sort order also determines the property that the CeSeekDatabase function uses to traverse the database.

The following code example demonstrates the call to CeOpenDatabase.

CEOID objId;                        // database ID
TCHAR szDbName[MAX_SIZE];           // contains the database name
HANDLE hDb;                         // handle to the database
...
hDb = CeOpenDatabase(&objId,        // tmp location for the database id
                     szDbName,      // database name
                     0,             // sort order; 0 indicates ignore
                     CEDB_AUTOINCREMENT, // flags
                     NULL);         // window handle for notifications
// perform error checking on hDb handle before continuing...
// perform other operations on the database, then close it
CloseHandle(hDb);

For more information about sort order, see Sorting Records. For more information about moving the seek pointer, see Searching for Records.