Unrecognised database format with ACCESS and ADO

  ado, c++, ms-access, visual-c++

ALL,

I have a MS Access accdb file, to which I try to connect:

    std::wstring dbFile = pimpl->m_connectString.substr( pimpl->m_connectString.find( L"DBQ=") + 4 );
    dbFile = dbFile.substr( 0, dbFile.find( L";" ) );
    if( FAILED( CoInitialize( NULL ) ) )
    {
        errorMsg.push_back( L"Failed to initialize DAO interface" );
        result = 1;
    }
    if( !result )
    {
        LPCSTR version;
        std::wstring connectString = L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
        connectString += dbFile;
        _bstr_t strCnn( connectString.c_str() );
        _ConnectionPtr pConnection = NULL;
        try
        {
            if( FAILED( pConnection.CreateInstance( __uuidof( Connection ) ) ) )
            {
                errorMsg.push_back( L"Failed to create a connection to ACCESS engine" );
                result = 1;
            }
            else
            {
                pConnection->Open( strCnn, "", "", adConnectUnspecified );
                version = (LPCSTR) (_bstr_t) pConnection->Properties->GetItem("DBMS Version")->Value;
            }
        }
        catch( _com_error &e )
        {
            ErrorPtr pErr = NULL;
            if( ( pConnection->Errors->Count ) > 0 )
            {
                long nCount = pConnection->Errors->Count;
                // Collection ranges from 0 to nCount -1.
                for( long i = 0 ; i < nCount ; i++ )
                {
                    std::wstring error = L"Error is ";
                    pErr = pConnection->Errors->GetItem( i );
                    std::string descr( ((LPCSTR) pErr->Description) );
                    printf( "Error number: %xt%sn", pErr->Number, (LPCSTR) pErr->Description );
                }
            }
        }
        CoUninitialize();

However upon execution I’m getting aforementioned error.

What am I missing?

I am working with MSVC 2017 Community on Windows 8.1.

I have no idea what engine the file was created with.

TIA!

Source: Windows Questions C++

LEAVE A COMMENT