PDA

View Full Version : Access ODBC SQLDisconnect Segmentation Fault



KaptainKarl
2nd November 2010, 14:29
QT: 4.7 commercial
OS: Windows 7
IDE: QT Creator 2.0.1
Installed using QT SDK 2010.05

I am using a console application and the QT ODBC driver to connect to and append an Access database file. The db open() and query exec() methods return "true". However, the data does not appear in the database. When the main function returns, a segmentation fault occurs in the ODBC driver code at SQLDisconnect.

Connection code:

static bool connectToDB() { static QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); QString sDBFile = "S:/Current_b416net.mdb"; QString sDBDriver = "DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=" + sDBFile; db.setDatabaseName(sDBDriver); return db.open(); }

Connection usage:


if (!connectToDB()) <---Returns true.
{ Logger("Unable to connect to Database."); return 3; }

Query Code:


QString sQTxt = "INSERT INTO log \n" "(index, system, \n" " event, log) \n" "VALUES ('" + sIndex + "', '" + sIP + "', \n" " '" + sType + "', '" + sMessage + "')"; Logger(sQTxt); QSqlQuery qEvent; if (!qEvent.exec(sQTxt)) { Logger("... Query for event insertion failed."); Logger(qEvent.lastError().text()); Logger(sQTxt); qEvent.clear(); return false; } else { cvtLogger("... Query successful."); <-- Code takes this branch. qEvent.clear(); return true; }

The segmentation fault occurs as the main function returns. The IDE jumps to this location in qsql_odbc.cpp:


// Open statements/descriptors handles are automatically cleaned up by SQLDisconnect if (isOpen()) { r = SQLDisconnect(d->hDbc); <---- Current line is here. if (r != SQL_SUCCESS) qSqlWarning(QLatin1String("QODBCDriver::disconnect: Unable to disconnect datasource"), d); else d->disconnectCount++; }

Anybody have some experience that might help me?

Karl