Qt database



  • hiii...this is my first database app using Qt and i dont know what is wrong any help??

    @#include <QtCore/QCoreApplication>
    #include <QtSql>
    #include <QDebug>
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    //127.0.0.1
    QString servername = "localhost\SQLEXPRESS";
    QString dbname = "MyDatabase";

    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setConnectOptions();
    
    QString dsn = QString("DRIVER={SQL Native Client};SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername).arg(dbname);
    db.setDatabaseName(dsn);
    if(db.open())
    {
        qDebug()<<"connected finallyyyyyyyyyy :D:D:D:D";
    }else{
        qDebug()<<db.lastError().text();
        qDebug() << QSqlDatabase::drivers();
    }
    return a.exec(&#41;;
    

    }
    @



  • And the output is?



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



  • Seems that your data source isn't set up properly. Can you access it from other software (e.g. MS Access Or OO) through ODBC?



  • ok thx alot...what will be the server name if i will use MS access??...excuse my bad question I am a DB beginner ;)



  • "This":http://www.connectionstrings.com/ will help you.



  • thank you very much =)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.