问:如何打开SQL Compact Server文件.sdf

时间:2015-08-28 19:47:13

标签: c++ sql-server database qt sdf

我正在尝试使用Qt打开SQL Compact服务器文件.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

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

\用于C ++中的escape sequences,所以你需要这样做:

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