CDaoWorkspace::CompactDatabase

static void PASCAL CompactDatabase( LPCTSTR lpszSrcName, LPCTSTR lpszDestName, LPCTSTR lpszLocale = dbLangGeneral, int nOptions = 0 );
throw( CDaoException, CMemoryException );

static void PASCAL CompactDatabase( LPCTSTR lpszSrcName, LPCTSTR lpszDestName, LPCTSTR lpszLocale, int nOptions, LPCTSTR lpszPassword );
throw( CDaoException, CMemoryException );

Parameters

lpszSrcName

The name of an existing, closed database. It can be a full path and filename, such as “C:\\MYDB.MDB”. If the filename has an extension, you must specify it. If your network supports the uniform naming convention (UNC), you can also specify a network path, such as “\\\\MYSERVER\\MYSHARE\\MYDIR\\MYDB.MDB”. (Double backslashes are required in the path strings because “\” is the C++ escape character.)

lpszDestName

The full path of the compacted database that you are creating. You can also specify a network path as with lpszSrcName. You cannot use the lpszDestName argument to specify the same database file as lpszSrcName.

lpszPassword

A password, used when you want to compact a password-protected database. Note that if you use the version of CompactDatabase that takes a password, you must supply all parameters. Also, because this is a connect parameter, it requires special formatting, as follows: ;PWD=lpszPassword. For example: ;PWD=“Happy”. (The leading semicolon is required.)

lpszLocale

A string expression used to specify collating order for creating lpszDestName. If you omit this argument by accepting the default value of dbLangGeneral (see below), the locale of the new database is the same as that of the old database. Possible values are:

nOptions

Indicates one or more options for the target database, lpszDestName. If you omit this argument by accepting the default value, the lpszDestName will have the same encryption and the same version as lpszSrcName. You can combine the dbEncrypt or dbDecrypt option with one of the version options using the bitwise-OR operator. Possible values, which specify a database format, not a database engine version, are:

Remarks

Call this member function to compact a specified Microsoft Jet (.MDB) database. As you change data in a database, the database file can become fragmented and use more disk space than necessary. Periodically, you should compact your database to defragment the database file. The compacted database is usually smaller. You can also choose to change the collating order, the encryption, or the version of the data format while you copy and compact the database.

! WARNING   The CompactDatabase member function will not correctly convert a complete Microsoft Access database from one version to another. Only the data format is converted. Microsoft Access-defined objects, such as forms and reports, are not converted. However, the data is correctly converted.

Tip   You can also use CompactDatabase to copy a database file.

For more information about workspaces, see the article DAO Workspace in Visual C++ Programmer's Guide. For more information about compacting databases, see the topic "CompactDatabase Method" in DAO Help.

CDaoWorkspace OverviewClass MembersHierarchy Chart

See Also   CDaoWorkspace::RepairDatabase