PDA

View Full Version : Qt how to open SQL Compact Server file .sdf



ketest
31st August 2015, 18:53
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



In the past I have connected to MS Access database by using


db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=C:\\temp\\TestEng_TestDatabas e.accdb");


Not sure what I should be putting for
"Driver={???}

ChrisW67
31st August 2015, 22:06
There is no out-of-the-box ODBC driver for Sql Server Compact Ed AFAICT. Your options are limited to .Net or OLEDB interfaces.

ketest
2nd September 2015, 18:02
So what does that mean? Qt cannot open a SQL compact server file?
How would I implement the .Net or OLEDB interface in Qt?

ChrisW67
3rd September 2015, 11:20
There is no ODBC support for Sql Server Compact Ed and therefore the standard Qt ODBC Sql database driver cannot access it.

Your C++ program can access Sql Server Compact Ed databases using the Microsoft OLE DB API directly.
You may also be able to access the data through ActiveQt.
You could, of course, write a Qt SQL driver specifically for Sql Server Compact Ed.