Problems with Open-Source Downloads read and

QSqlDatabase problem (QODBC)

  • Hello,

    I am trying to connect at a database in SQL Server 2008. This last seems to be correctly installed (because I can create database and tables), and in addition, my C# program can connect in a database with success.

    So, I've wrote the following lines in Visual C++ Express :
    QSqlDatabase sql_test = QSqlDatabase::addDatabase("QODBC");
    bool ok =;
    QMessageBox::information(this, "Connexion SQL", "Connexion SQL réussite !");
    QMessageBox::warning(this, "Connexion SQL", "Connexion SQL échoué !");
    QSqlError *checkError= new QSqlError(sql_test.lastError());
    QMessageBox::information(this, "", checkError->text());

    There is the result in french :
    In english, it is : "data source name not found and no default driver specified"

    For me, it could be wrong specification that I should give to QSqlDatabase object, but I've tried other solutions like
    I didn't have any username and password :s

    Here is the following lines to connect in C#, just to show that I just needed to specificate Server and database to make it work.
    @ = "Server=SYLRA-PC\SQLEXPRESS;DataBase=quiz_games;Trusted_Connection=yes";

    Double antislash is to escape the first. I tried with only one and the slash, same errors.

    Here is how I am connected in SQL Management :

    Thanks you.

  • It looks like the ODBC driver is loaded (if I understand the message in French correctly), but the connection string is incorrect. From the documentation:
    [quote]Be aware that when connecting to an ODBC datasource you must pass in the name of the ODBC datasource to the QSqlDatabase::setDatabaseName() function rather than the actual database name.[/quote]

    The documentation is a bit too well-hidden unfortunately. Read all about using QODBC "here":

Log in to reply