0

我正在尝试使用 Qt 打开一个 SQL Compact Server 文件 .sdf。我有以下代码:

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);

我收到错误消息:

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

我得到:

db.open(): Success/Fail = Fail

我该如何解决这个问题?

4

1 回答 1

1

\用于C++ 中的转义序列,因此您需要这样做:

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

于 2015-08-28T20:06:15.697 回答