Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlDatabase problem (QODBC)
Forum Update on Monday, May 27th 2025

QSqlDatabase problem (QODBC)

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sylra
    wrote on 27 Feb 2011, 12:09 last edited by
    #1

    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");
    sql_test.setHostName("SYLRA-PC\SQLEXPRESS");
    sql_test.setDatabaseName("quiz_games");
    bool ok = sql_test.open();
    if(ok)
    {
    QMessageBox::information(this, "Connexion SQL", "Connexion SQL réussite !");
    }
    else
    {
    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 :
    !http://uploads.siteduzero.com/files/297001_298000/297821.png(Here)!
    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
    @
    db.setUserName("");
    db.setPassword("");
    @
    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.
    @
    Global.cn.ConnectionString = "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 :
    !http://uploads.siteduzero.com/files/297001_298000/297822.png(Here)!

    Thanks you.
    Sylra

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dialingo
      wrote on 28 Feb 2011, 10:17 last edited by
      #2

      see:
      "http://www.qtcentre.org/threads/38008-QSqlDatabase-QODBC-driver-not-loaded":http://www.qtcentre.org/threads/38008-QSqlDatabase-QODBC-driver-not-loaded

      [EDIT: fixed link, Volker]

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on 28 Feb 2011, 10:30 last edited by
        #3

        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":http://doc.qt.nokia.com/4.7/sql-driver.html.

        1 Reply Last reply
        0

        1/3

        27 Feb 2011, 12:09

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved