Connect to access data base in win32 and x64 with odbc driver
-
Hello,
My Qt application designed on Win32 works fine to connect to an access database through odbc driver.
Since, I generated this application with x64, so it cannot connect with the access database.versions
- windows 7 pro
- visual studio 2008
- qt V4.6.2
- toto.mdb is the access file generated by access 2003
The win32 configuration files :
- odbccad32 in Windows\SysWOW64 with odbcad32 that drives Microsoft Access Driver (*.mdb) Version 6.01.7601.17632
- odbc32.dll in Windows\SysWOW64 v6.1.7601.17514
- odbcint.dll in Windows\SysWOW64 v6.1.7600.16385
- The qt dll plugins is:
.\Debug\sqldrivers\qsqlodbcd4.dll
The x64 configuration files
- I have installed Microsoft Access Database Engine 2010 Redistributable
- odbccad32 in Windows\system32 with odbcad32 that drives Microsoft Access Driver (*.mdb, *.accdb) Version 14.00.4760.1000
- odbc32.dll in Windows\system32 v6.1.7601.17514
- odbcint.dll in Windows\system32 v6.1.7600.16385
- The qt dll plugins is:
.\Debug\sqldrivers\qsqlodbcd4.dll
@QString dbName;
QSqlDatabase m_db;
m_db = QSqlDatabase::addDatabase("QODBC");
dbName = "DRIVER={Microsoft Access Driver (*.mdb)};DSN='';DBQ=toto.mdb";
m_db.setDatabaseName(dbName);
m_db.setConnectOptions("SQL_ATTR_ACCESS_MODE=SQL_MODE_READ_ONLY");the source code
if(m_db.open())
{
qDebug() << "oK";
m_db.close();
}
else
{
qDebug() << m_db.lastError().text();
}@Dll log is:
- .\Debug\sqldrivers\qsqlodbcd4.dll is loaded
- Windows\system32\odbc32.dll is loaded
- Windows\system32\odbcint.dll is loaded
Error log is :
- Error in french: [Microsoft][Gestionnaire de pilotes ODBC] Source de données introuvable et nom de pilote non spécifié QODBC3: Unable to connect
Error in english: [Microsoft] [ODBC Driver Manager] Data source name not found and no default driver specified.
Help please !
-
I solved this problem, and now my application generated wih x64 connects to Access Data Base.
The name of the driver must be written exactly as you see on ODBC management: Windows\system32\odbccadd32. The ODBC driver for access shows : DRIVER={Microsoft Access Driver (*.mdb, *.accdb)
source code
@#ifdef _WIN64
dbName = "DRIVER={Microsoft Access Driver (*.mdb, .accdb)}'';DBQ=toto.mdb";
#else
dbName = "DRIVER={Microsoft Access Driver (.mdb)};DBQ=toto.mdb";
#endif@The driver odbc for access x64:
http://www.microsoft.com/en-us/download/details.aspx?id=13255