Opening database with ADO in C++ throws exception in x64

Peter Mortier 1 Reputation point
2022-02-22T15:56:08.103+00:00

I am running a small program in x64 mode (Visual Studio 2019) for opening a database :

#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \  
   no_namespace rename("EOF", "EndOfFile")  
#include "icrsint.h"  
_COM_SMARTPTR_TYPEDEF(IADORecordBinding, __uuidof(IADORecordBinding));  
_ConnectionPtr m_pConnectionPtr = 0;  
int main()  
{  
  HRESULT hr = CoInitialize(NULL);  
  m_pConnectionPtr = NULL;  
  m_pConnectionPtr.CreateInstance(__uuidof(Connection));  
  bstr_t strCnn(R"(Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=c:\myDatabase.accdb;User ID=sa;)");  
  m_pConnectionPtr->Open(strCnn, "", "", NULL);  
  m_pConnectionPtr->Close();  
}  

Running this an exception is thrown in msado15.tli :

176866-exception.jpg

This exception messes with my stack.
When doing this x86 I do not have this exception.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,801 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,690 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 84,546 Reputation points
    2022-02-22T16:43:04.497+00:00

    This works for me with ACE Driver, in x86 or x64, in Unicode (remove the password for your accdb file... ) :

                {
                    _ConnectionPtr m_pConnectionPtr = 0;
                    HRESULT hr = CoInitialize(NULL);
                    m_pConnectionPtr = NULL;
                    m_pConnectionPtr.CreateInstance(__uuidof(Connection));
                    _bstr_t strCnn("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\\employees.accdb;Jet OLEDB:Database Password=toto;");
                    m_pConnectionPtr->Open(strCnn, L"", L"", NULL);
                    m_pConnectionPtr->Close();
                }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.