Creating .Mdb Files Programmatically

Use the SQLConfigDataSource function to add, modify, or delete a data source dynamically. If you call SQLConfigDataSource with a window handle, data source setup is performed interactively through the Setup dialog box. If you call the function with a NULL window handle, the data source is set up by using keywords that are contained in the lpszAttributes argument.

SQLConfigDataSource takes as arguments the type of request (add, configure, or remove), the name of the driver, and a list of keyword-value pairs. The following keyword-value pairs are used to add, modify, or delete a file.

Keyword Description
DBQ The name of the database file
DEFAULTDIR The path to the database file for Microsoft Access, or the directory for the other drivers
DESCRIPTION A description of the data in the data source
DRIVER The path specification for the driver
DRIVERID An integer ID for the driver (“25” for Microsoft Access)
FIL The file type (Microsoft Access)
JETINIPATH The path to the Microsoft Jet initialization file
PWD A password
READONLY Indicates whether the file is read-only (TRUE) or not (FALSE)
SYSTEMDB The path to the system database file
UID The user ID name used for logging on

See Also For a complete specification of the keywords, see the Microsoft ODBC Desktop Database Drivers Help file (ODBCJET.HLP).

To perform the following operations on a Microsoft Access database file, or to set the following settings, include the appropriate keyword in the call to SQLConfigDataSource.

Keyword Description
COMPACT_DB Compacts data. See the “Database Compaction ” section later in this chapter.
CREATE_DB Creates a Microsoft Access database file. (If the path contains a space, the entire path must be enclosed in double quotation marks.)
CREATE_SYSDB Creates a system database. This keyword takes the database name and the desired sort order as arguments.
CREATE_V2DB Creates a database that is compatible with Microsoft Access 2.0. This keyword takes the database name and the desired sort order as arguments.
EXCLUSIVE Opens the database so that it can be accessed by only one user at a time (EXCLUSIVE=TRUE), or by more than one user at a time (EXCLUSIVE=FALSE).
IMPLICITCOMMIT
SYNC
Indicates whether implicit commits are performed asynchronously. A value of YES (the default) means that the driver will wait for commits in an implicit transaction to be completed.
MAXBUFFERSIZE Indicates the size of the internal buffer, in kilobytes, that is used to transfer data to and from the disk. Any integer value divisible by 256 can be used. The default is 512 KB.
MAXSCANROWS Indicates the number of records (rows) to be scanned when a field’s data type is set based upon existing data. A number from 1 to 16 can be entered; a value of 0 means all records will be scanned.
PAGETIMEOUT Indicates the period of time, in tenths of a second, that a page (if not used) remains in the buffer before being removed.
REPAIR_DB Repairs a file damaged during the commit process. See the “Database Repair ” section later in this chapter.
SAFETRANSACTIONS If this is 1, it indicates that transactions will be committed immediately, without the delay specified by the PAGETIMEOUT value. If this is 0, it indicates that transactions will be truly committed when the operating system flushes the data to disk.
THREADS The number of background threads for the engine to use.
USERCOMMITSYNC Indicates whether user-defined transactions are performed asynchronously. A value of YES (the default) means that the driver will wait for commits in a user-defined transaction to be completed.

All of the previously listed values are used for Microsoft Jet files, but this is not a complete list of the keywords that can be used in a call to SQLConfigDataSource. Other keywords can be used for other drivers.