Article ID: 149558 - View products that this article applies to.
This article was previously published under Q149558
Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code. Microsoft Visual C++ 2005 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model.
Prior to the release of the Microsoft ODBC Desktop Driver Pack version 2.0, there was no way to programmatically create a Microsoft Access database (an .mdb file). For more details about this, please see the following article in the Microsoft Knowledge Base:
118609With the release of the version 2.0 driver pack and higher, MFC ODBC applications can now create .mdb files. Additionally, with the incorporation of DAO into Visual C++ 4.x or higher, you have another way to create Microsoft Access databases programmatically.
(http://support.microsoft.com/kb/118609/EN-US/ )How To Create an .MDB File for Microsoft Access Databases
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:
hwndParent is either NULL if no dialogs are to be displayed or a valid hwnd to act as parent to any driver generated dialogs.NOTE: Unlike most other ODBC API functions, SQLConfigDataSource returns a boolean value. This return value is TRUE if the .mdb was created, FALSE if creation failed.
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:
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:
Sample CodeUse of SQLConfigDataSource ODBC installer DLL API function:
This will create ATest.mdb in the application's working directory using general sorting.
"Inside ODBC" by Kyle Geiger, Microsoft Press ISBN 1-55615-815-7.
For more information, please see the following article in the Microsoft Knowledge Base in the ODBC collection:
(http://support.microsoft.com/kb/126606/EN-US/ )INFO: Accessing CREATE_DB, REPAIR_DB, and COMPACT_DB
Article ID: 149558 - Last Review: December 31, 2005 - Revision: 4.0