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. Qt database
Qt 6.11 is out! See what's new in the release blog

Qt database

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.7k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    ahmed kato
    wrote on last edited by
    #1

    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;;
    

    }
    @

    Ahmed Kato
    Computer & communications student
    Intern and MSP at Microsoft

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      And the output is?

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ahmed kato
        wrote on last edited by
        #3

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

        Ahmed Kato
        Computer & communications student
        Intern and MSP at Microsoft

        1 Reply Last reply
        0
        • L Offline
          L Offline
          loladiro
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ahmed kato
            wrote on last edited by
            #5

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

            Ahmed Kato
            Computer & communications student
            Intern and MSP at Microsoft

            1 Reply Last reply
            0
            • L Offline
              L Offline
              loladiro
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • A Offline
                A Offline
                ahmed kato
                wrote on last edited by
                #7

                thank you very much =)

                Ahmed Kato
                Computer & communications student
                Intern and MSP at Microsoft

                1 Reply Last reply
                0

                • Login

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