Reputation: 111
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
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