Operating Environment: Win7 64
vc++6.0
Office 2007 32-bit (Access 2007)
I'm using ADO to connect to an Access database, which is typically 32-bit office installed in the WIN7 system because Microsoft recommends 32-bit office, which is more compatible and more stable. The Access file is an. mdb (2003 format that prompts you without the Jet access component). ACCDB (2007 format)), so you need to install Accessdatabaseengine_ X64.exe driver, you will be prompted to uninstall Office and install 64-bit office before installing. Can be installed using the "/passive" command;
The operation is as follows:
- Open the command line Input accessdatabaseengine_x64.exe/passive installation is complete.
- After the installation is complete, review the registry hkey_local_machine\software\microsoft\office\14.0\common\filespaths, remove Mso.dll (be sure to do this step, otherwise the Office Config configuration issue, office will reinstall Office when started
When the above preparation is done, you can begin coding the following key codes:
CoInitialize (NULL);
_connectionptr Pconn (__uuidof (Connection));
_RecordsetPtr pRst (__uuidof (Recordset));
_bstr_t strconnect= "uid=;p wd=;D river={microsoft Access DRIVER (*.mdb)};D bq=c:\\mac.mdb;";
Pay special attention to the connection string here or use the following connection string (it is easy to make mistakes, these 2 are all right, I've wasted a lot of time on this one.
/*
_bstr_t strconnect= "uid=;p wd=;D river={microsoft Access DRIVER (*.mdb)};D bq=c:\\mac.mdb;";
_bstr_t strconnect= "Driver={microsoft Access DRIVER (*.mdb)};D bq=c:\\mac.mdb;uid=;p wd=;";
*/
Pconn->open (StrConnect, "", "", adModeUnknown);
Prst=pconn->execute ("SELECT * from MacAddress", Null,adcmdtext);
while (!prst->adoeof)
{
((clistbox*) GetDlgItem (idc_list1))->addstring ((_bstr_t) prst->getcollect ("Mac"));
printf ("%s \ n", Prst->getcollect ("Mac"));
Prst->movenext ();
}
Prst->close ();
Pconn->close ();
Prst.release ();
Pconn.release ();
CoUninitialize ();
Tip [Microsoft][ODBC Driver Manager] does not discover the data source name and does not specify a default driver, most likely the driver is already installed, but the connection string is incorrect (such as the Access file path).
Win7 + VC + + ADO way to connect to an access connection string