Using a DSN to connect my QT application to MSSQL Server 2005



  • So here is my little code snibbit that i use to connect to my database:
    @
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setHostName("194.47.150.169");
    db.setDatabaseName("mytest");
    //db.setDatabaseName("DRIVER={SQL Server};SERVER=194.47.150.169;DATABASE=MYDB;UID=UID;PWD=PWD");

    if(db.open())
    {
        this->setWindowTitle("Database connected well");
        db.close();
    }
    else
    {
        QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
    }
    

    @

    The error i get in my messagebox is:
    [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user". The user is not associated with a trusted SQL Server connection. QODBC3: Unable to connect.

    I am using a remote server to connect to and using the MSSQL management studio i can connect to that address using the real ID and PW and when i added the DNS with odbcad32.exe and tested the connection there was no problem.
    The part i commented away works if i use that way to connect. The name of the DNS and what is written in my code is the same.

    It seems to me that its something wrong with my DNS but i cant figure out what. Hope you can help me.


Log in to reply
 

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