0

I have a csv file that I'd like to parse in Qt. I'd like to use the sql plugin, but I'm not sure how to get things set up. I currently am unable to open the .csvfile from my Qt app--I have to manually open it then start my app in hopes to query from it.

If the file I'm trying to read isn't manually opened before I begin my app, I get the following driver error:

[Microsoft][ODBC Excel Driver] External table is not in the expected format.
[Microsoft][ODBC Excel Driver] General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x1ae0 Thread 0x1f2c DBC 0x4c52a4 Excel.' QODBC3: Unable to connect.

Here's my setup...

Qt Creator Build/Version:

  • I am working in Qt 5.3 which I did not build from source--I downloaded the installer.
  • I have configured a few debugging kits, but the one i'm using currently uses the MSVC 2012 openGL 32 bit compiler (which I've got set to default).
  • I have both Visual Studio 2012 AND 2010 on my machine, which is 64bit.
  • I didn't have to make the sql drivers, they came installed already (available drivers: () ("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7"))

My .pro file hooks to the sql plugin:

QT       += core gui network sql

And I've got the following includes:

#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>

This is my code that establishes an Excel database connection and attempts a query:

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
QString pathString = QString("C:\\MY_FILES\\test_work\\Xena\\Xena2544-2G\\Reports\\asdf_SN1_RFC2544_7_port_verify.csv");


db.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls)};DBQ=" + pathString );

 if (!db.open())
{

    QSqlError er = db.lastError();
    QMessageBox::information(0, "Error", er.text());

}
if(db.open())
{
    QSqlQuery query("select * from [" + QString("asdf_SN1_RFC2544_7_port_verify") + "$B13]");  //NEVER GETS HERE UNLESS i ALREADY MANUALLY OPENED THE FILE BEFORE RUNNING CODE.

        QString process1Result = query.value(0).toString();
        ui->verifyUnit1Status_lb->setText(process1Result);

}

File Permissions - Full control - modify - read& execute - read - write

I'd really like to get this feature going. I would assume the error is in the connection string, but at this point I've tried for a couple hours with no success.

Thank you in advance.

Rachael
  • 1,965
  • 4
  • 29
  • 55
  • did You try 'db.setDatabaseName("DRIVER={Microsoft Excel Driver (*.csv)};' – a_manthey_67 Apr 19 '15 at 10:18
  • @a_manthey_67 yep :( no luck. Coming back to this later this week to solve once and for all, hopefully. I can parse the text file as CSV, but this defeats the purpose of looking at it using the ODBC driver--so that we can hopefully write back to the excel file in a more advanced format. I'm leaning toward just dealing with files as CSV since there is such a driver-machine compatibility issue. – Rachael Apr 20 '15 at 18:16

0 Answers0