简体   繁体   中英

Connecting to Firebird database in Qt

I have local database, that I want to connect with. Here is my code, but unfortunately it doesn't work.

    QString servername = "SYSDBA@localhost";
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setHostName(servername);     
    db.setDatabaseName("Driver={InterBase ODBC driver};DATABASE=D:\\baza\\BAZA.fdb;");      
    db.setUserName("SYSDBA");
    db.setPassword("masterkey");
    if (db.open())
        qDebug() << "Connected";
    else
        qDebug() << "Nope :(";  

I would appreciate any help.

I finally got it. You have to set up your ODBC driver in windows: https://kb.brainwaregroup.com/operationsmanager/faces/kb/brainwaregroup%20kb/article/AA-00486

Then you can connect it directly using dsn configured in windows administrative tools:

QString servername = "localhost";
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setHostName(servername);
db.setDatabaseName("YOUR_DSN_NAME");
db.setUserName("SYSDBA");
db.setPassword("masterkey");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM