Kevin Eisinger
Kevin Eisinger

Reputation: 111

Qt how to open SQL Compact Server file .sdf

I am trying to open a SQL Compact Server file .sdf with Qt. I have the following code:

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("C:\\testresults.sdf");
bool Success = db.open();

sprintf(writeToMonitorBuffer, "dblastError = %s", (const char *)db.lastError().text().toLatin1());
writeToMonitor(writeToMonitorBuffer);

sprintf(writeToMonitorBuffer, "db.open(): Success/Fail = %s", Success ? "Pass" : "Fail");
writeToMonitor(writeToMonitorBuffer);

I am getting the error message:

dblastError = [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect

And I get:

db.open(): Success/Fail = Fail

How can I solve this?

Upvotes: 0

Views: 750

Answers (1)

VB_overflow
VB_overflow

Reputation: 1773

\ is used for escape sequences in C++, so you need to do it like this instead:

db.setDatabaseName("C:\\testresults.sdf");

Upvotes: 1

Related Questions