0

I have a CDatabase.

One of my users has Access 2021 x64 installed. He runs the 64 bit edition of my software.

It opens a database like this:

CString strDBConnectString = L"Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=<path to db>;Pwd=";
m_Database.OpenEx(strDBConnectString, CDatabase::noOdbcDialog)

It refused to work on his PC and shows:

enter image description here

Why is it showing this? My development PC has Office 365 x64 and the same code works fine.

So what underlying issue is forcing this window to display?


Are you sure that the required driver you ask for is installed under this name? Yes, I am. This is because I do not use a literal text value here but I detect it by examining the JET drivers list:

// We now iterate the JET drivers list and locate a valid MDB driver
CString CCommunityTalksApp::GetJETDriverEx(bool bAccDbMode)
{
    CString         strDriver;
    CString         strName, strNameLower, strValue;
    CString         strDefaultDriver = _T("Microsoft Access Driver (*.mdb)");
    CString         strDBType = _T("(*.mdb)");
    CStringArray    aryStrDrivers;
    TCHAR           szBuf[2001]{};
    WORD            cbBufMax = 2000;
    WORD            cbBufOut;
    TCHAR* pszBuf = szBuf;

    if (SQLGetInstalledDrivers(szBuf, cbBufMax, &cbBufOut))
    {
#ifdef _WIN64
        strDefaultDriver = _T("Microsoft Access Driver (*.mdb, *.accdb)");
        strDBType = _T("(*.mdb, *.accdb)");
#else
        if (bAccDbMode)
        {
            strDefaultDriver = _T("Microsoft Access Driver (*.mdb, *.accdb)");
            strDBType = _T("(*.mdb, *.accdb)");
        }
#endif

        while (*pszBuf)
        {
            strName = CString(pszBuf);
            strNameLower = strName;
            strNameLower.MakeLower();

            if (strNameLower.Find(strDBType) != -1)
            {
                aryStrDrivers.Add(strName);
                if (strName.CollateNoCase(strDefaultDriver) == 0)
                {
                    strDriver = strName;
                    break;
                }
            }

            pszBuf += strName.GetLength() + 1;
        }


        if (strDriver.IsEmpty() && aryStrDrivers.GetSize() > 0)
        {
            // Try and use the first MDB driver we found
            strDriver = aryStrDrivers.GetAt(0);
        }
    }

    // Make a note of the driver
    AfxGetApp()->WriteProfileString(_T("Options"), _T("JET Connection Driver"), strDriver);

    return strDriver;
}
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • What is the `L` for? I presume you have an actual path in place of ``. – June7 Feb 01 '23 at 21:12
  • 1
    Naive question, is the ODBC driver installed on the client machine? It's name must be entered exactly as it appears in the installed driver description (install & run the ODBC Data Source Administrator application). Maybe missing some [redistributable](https://www.microsoft.com/en-us/download/details.aspx?id=54920)? Also, is the [connection-string](https://www.connectionstrings.com/access/) correct? These should best be in some configuration file or in the registry (you will have to implement a "Connection Settings" dialog - user-editable). – Constantine Georgiou Feb 01 '23 at 21:16
  • @ConstantineGeorgiou I ran the ODBC x64 Drivers and it was listed there. I can manually start Access. I also tried the 365 redistributable as there does not seem to be a 2021 version – Andrew Truckle Feb 01 '23 at 21:18
  • 1
    Found [this](https://help.interfaceware.com/v6/connect-to-microsoft-access-odbc). Sorry, can't help any further. – Constantine Georgiou Feb 01 '23 at 21:24
  • 1
    Are you sure that the required driver you ask for is installed under this name? – xMRi Feb 02 '23 at 13:03

0 Answers0