Win7 + VC + + ADO way to connect to an access connection string

Source: Internet
Author: User
Tags driver manager

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:

    1. Open the command line Input accessdatabaseengine_x64.exe/passive installation is complete.
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.