Using the Microsoft Access ODBC Driver to Create .MDB FilesKyle Geiger's book "Inside ODBC" provides a sample program, ODBCACC, that nicely demonstrates how to use the ODBC installer DLL API function SQLConfigDataSource to create an .mdb file. The syntax of the function call is:
BOOL SQLConfigDataSource(hwndParent, fRequest, lpszDriver,
fRequest is ODBC_ADD_DSN to specify creation of the .mdb file.
lpszDriver is Microsoft Access Driver (*.mdb).
lpszAttributes is "CREATE_DB=<path><filename>.mdb <sort order>\0" where the <path><filename> combination identifies where the file should be created and <sort order> is language sorting order (for example, General). <path> must be specified even if the .mdb is to be created in the current working directory. Use standard relative path syntax.
To use the installer DLL functions, you must:
- Use #include <ODBCINST.H>.
- Link with Odbcinst.lib for 16-bit applications.
- Link with Odbccp32.lib for 32-bit applications.
Using DAO to Create .MDB FilesDAO allows applications developed with Visual C++ 4.x to interface with the Microsoft Jet database engine directly. This allows more efficient manipulation of Microsoft Access objects than can be achieved through ODBC, including the creation of .mdb files. For a sample program that demonstrates how to create databases and other objects, search the Microsoft Knowledge Base for the DAOTABLE sample.
Note To compile this sample in Visual C++ .NET 2002 and Visual C++ .NET 2002, change the following line or lines in the code:
theControl->m_hWnd; to pDX->m_idLastControl =
Sample CodeUse of SQLConfigDataSource ODBC installer DLL API function:
fCreated = SQLConfigDataSource(NULL,
"Microsoft Access Driver (*.mdb)",
"CREATE_DB=.\\ATest.mdb General\0" );
For more information, please see the following article in the Microsoft Knowledge Base in the ODBC collection:
Article ID: 149558 - Last Review: Dec 30, 2005 - Revision: 1