Using CDatabase to open a ACCDB file is displaying a Select Database Source window

94 Views Asked by At

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;
}
0

There are 0 best solutions below