PDA

View Full Version : Transactions in Microsoft Access



PinTxO
29th May 2018, 09:38
Hi guys.

I have a database (.mdb) and I connect to it from my QT application. I do not have problems to read the data but when I save it, I want to do it through a transaction and I can not because I'm having an error. I paste how I open the connection and how I launch the transaction:

The connection:

m_db = QSqlDatabase::addDatabase("QODBC");
QString strPathDDBB="DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=" + QCoreApplication::applicationDirPath() + "/galibo.mdb";
m_db.setDatabaseName(strPathDDBB);
if (!m_db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"), m_db.lastError().text());
}
The transaction:
bool feature = m_db.driver()->hasFeature(QSqlDriver::Transactions);
if (!m_db.transaction())
{
error = "An error occurred while creating the transaction in the database\n";
error += m_db.lastError().text();
return false;
}

The feature variable returns true and the text error is "[Microsoft] [Microsoft Access ODBC Driver] Unable to define attribute now QODBC3: Unable to disable autocommit"

Any ideas?

PinTxO
30th May 2018, 09:00
I have already found out the reason for the error. The transaction is launched in the process of saving the application. Before this process, a series of consultations are made in the process of reading the information. Well, if in each query, the resources are not released through finish() method of the QSqlQuery class, then, when the transaction is launched, the commented exception is skipped.

Thank you