PDA

View Full Version : [Paradox] Connecting QT to Paradox Database



Zellus
24th May 2012, 16:25
Hello!
I'm learning QT for a few days and met a problem I can' solve for 2 days:/
I'm writing the application that downloads data from another's application database (Paradox 7.0). But I can't connect to that any way...
Here is my code:


#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QtSql/QtSql>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Provider=MSDASQL;Persist Security Info=False;Mode=Read;Extended Properties='DSN=Paradox;DBQ=C:\\Dane\\ST_RCP;Defau ltDir=C:\\Dane\\ST_RCP;DriverId=538;FIL=Paradox 7.X;MaxBufferSize=2048;PageTimeout=600;';Initial Catalog=C:\\Dane\\ST_RCP;");
if(db.open())
qDebug() << "Polaczenie z baza powiodlo sie";
else
qDebug() <<"Error: " << db.lastError ();
return a.exec();
}

Here is my error(In applications console)


Error: QSqlError<0, "QODBC3: Unable to connect", "[Microsoft][Menedzer sterowników ODBC] Nie można odnaleźć źródła danych, a nie ma podanego sterownika domyślnego">

Last part can be translated as "[Microsoft][ODBC drivers manager] Could not found data source, and there is not default value (given?)"

What can I do with that? Any usefull informations? I tried to use http://qt-project.org/doc/qt-4.8/qtsql.html but nothing helped;/

PS. This is sample code I wrote to learn connecting to database, not the one I wrote about in the beggining :P

Paradox 7.0, Windows 7(64bit), QT Creator 2.4.1, QT 4.7.4(32 bit)
plugins/sqldrivers <- done

Added after 35 minutes:

Problem Solved:


QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Paradox");
db.setUserName("Zellus");
db.setHostName("Paradox");
if(db.open())
qDebug() << "Success";
else
qDebug() <<"Error: " << db.lastError ();

Also you have to C://Windows/sysWOW64/odbcad32.exe run
and then Add>Driver to MS Paradox(*.db) (or other *.db, not sure what i did:P) Name Paradox, disable use default catalog, choose catalog and navigate to folder where database is ;]