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. QODBC driver not loaded
Forum Updated to NodeBB v4.3 + New Features

QODBC driver not loaded

Scheduled Pinned Locked Moved General and Desktop
32 Posts 4 Posters 20.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.
  • Z Offline
    Z Offline
    zidom
    wrote on last edited by
    #1

    Hi
    in the code below i have a problem with addDatabase("QODBC");
    it seems that my computer doesn't recognize QODBC how can i find the correct name for adding database i use microsoft sql server 2008 R2
    @#include <QCoreApplication>
    #include <QtSql>
    #include <QDebug>
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    QString servername = "TEST\EGHALSQL";
    QString dbname = "Test";
    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() << "Opened";
    db.close();
    }
    else
    {
    qDebug() <<"Error = "<<db.lastError();
    }
    return a.exec();
    }@

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hardcodes.de
      wrote on last edited by
      #2

      "According to this paragraph here":http://qt-project.org/doc/qt-4.8/sql-driver.html#qodbc you need to configure a ODBC connection in the ODBC connection manager in the control panel.
      The important part reads

      bq. 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.

      Bonus chatter: Using ODBC or not, get used to FQDN for the server name. Saves you from many problems in a "real environment".

      while(!sleep){++sheep;}

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zidom
        wrote on last edited by
        #3

        "On Windows an ODBC driver manager should be installed by default."
        i have windows how can i check ODBC is installed or not?

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hardcodes.de
          wrote on last edited by
          #4

          It is (as long as you use something >= XP), you must configure an ODBC connection: http://msdn.microsoft.com/en-us/library/ca6axakh(v=vs.80).aspx on each computer that should connect to the database via ODBC.

          while(!sleep){++sheep;}

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zidom
            wrote on last edited by
            #5

            I add odbc

            !http://dl.2rialy.ir/ZiDoM-Ups/91/odbc.JPG(odbc)!

            but i still have this error

            !http://dl.2rialy.ir/ZiDoM-Ups/91/sql.JPG(error)!

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hardcodes.de
              wrote on last edited by
              #6

              Please be so kind and provide some information.

              What Windows version do you use?
              Did you test the ODBC connection? How is it configured? Which driver is configured therein?
              Can you connect via OSQL?
              Do you still use the connection data from you initial post? If yes, it won't work. If no, what do you use now?
              What Qt library version do you use?
              32bit or 64bit?
              The latter one could be important, because the "database driver must exist":http://communities.bentley.com/other/old_site_member_blogs/bentley_employees/b/allen_brown_bentleys_blog/archive/2009/03/04/32-bit-database-connectivity-on-a-64-bit-os.aspx for the same "bitness" of your application.

              After all that is checked, it could still be a "bug":https://bugreports.qt-project.org.

              while(!sleep){++sheep;}

              1 Reply Last reply
              0
              • T Offline
                T Offline
                terenty
                wrote on last edited by
                #7

                [quote author="zidom" date="1350898907"]I add odbc

                !http://dl.2rialy.ir/ZiDoM-Ups/91/odbc.JPG(odbc)!

                but i still have this error

                !http://dl.2rialy.ir/ZiDoM-Ups/91/sql.JPG(error)![/quote]

                When I did this I also specified DSN in the string I passed to setDatabaseName(). In your case that would be ZiDoM (according to your pic) . The string should look smthng like this:
                @"DRIVER={SQL Native Client};DSN='ZiDoM';SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;"@
                P.S. I am not quite sure about the string syntax. I will post the one I used tommorow when I get to work.

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  zidom
                  wrote on last edited by
                  #8

                  Thanks because of helping
                  i use windows 7 64bit
                  i use qt 4.8
                  qt creator 2.5 based on 32 bit qt 4.8
                  i used DSN='ZiDoM' but didn't work still same error and i still use the code that i wrote in first post

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    terenty
                    wrote on last edited by
                    #9

                    This is the string that works fine for me:
                    @QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
                    db.setDatabaseName("Driver={SQL Server};DSN='PlaneTraj';SERVER=DB-SERVER;DATABASE=RealPlanesData;");@
                    My user DSN (that I added using C:\Windows\SysWOW64\odbcad32.exe) name is PlaneTraj and its Driver is SQL Server; in your case these are ZiDoM and SQL Server (according to your pic).
                    Try using Driver={SQL Server} instead of yours DRIVER={SQL Native Client}

                    S 1 Reply Last reply
                    1
                    • Z Offline
                      Z Offline
                      zidom
                      wrote on last edited by
                      #10

                      i tried that but still same error
                      i tried
                      QStringList driversList = QSqlDatabase::drivers();
                      qDebug() << "drivers list= " << driversList;
                      to see the drivers but there is no QODBC

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        terenty
                        wrote on last edited by
                        #11

                        Look inside the folder located somewhere like: C:\Qt\4.8.2\plugins\sqldrivers. See if it contains ODBC drivers.
                        I have the following files in this folder:
                        qsqlite4.dll qsqlite4.exp qsqlite4.lib qsqlited4.dll
                        qsqlited4.exp qsqlited4.ilk qsqlited4.lib qsqlited4.pdb
                        qsqlodbc4.dll qsqlodbc4.lib qsqlodbcd4.dll qsqlodbcd4.lib
                        qsqlpsql4.dll qsqlpsql4.lib qsqlpsqld4.dll qsqlpsqld

                        1 Reply Last reply
                        0
                        • Z Offline
                          Z Offline
                          zidom
                          wrote on last edited by
                          #12

                          I have them except the *.exp

                          1 Reply Last reply
                          0
                          • T Offline
                            T Offline
                            terenty
                            wrote on last edited by
                            #13

                            looks like your app for some reason can't locate theese files. have a look at this http://doc.qt.digia.com/latest/deployment-plugins.html

                            1 Reply Last reply
                            0
                            • Z Offline
                              Z Offline
                              zidom
                              wrote on last edited by
                              #14

                              you mean i should have those *.exp files?

                              1 Reply Last reply
                              0
                              • T Offline
                                T Offline
                                terenty
                                wrote on last edited by
                                #15

                                no, I don't know what .exp files are for, but I don't think it's the problem. I mean if you have all the rest qsqlodbc files in \sqldrivers and QSqlDatabase::drivers() doesn't give QODBC in the list, then maybe your app can't locate them in this folder?
                                does QSqlDatabase::drivers() return anything or the list is epmpty? if it does what is it?

                                1 Reply Last reply
                                0
                                • Z Offline
                                  Z Offline
                                  zidom
                                  wrote on last edited by
                                  #16

                                  it returns QSQLITE

                                  1 Reply Last reply
                                  0
                                  • T Offline
                                    T Offline
                                    terenty
                                    wrote on last edited by
                                    #17

                                    The only thing I can think of: make a backup of your \sqldrivers or just rename it and try to replace it with mine:
                                    http://zalil.ru/33883387/554c07b0.508763d8/sqldrivers.zip
                                    I am using qt4.8.3 though

                                    1 Reply Last reply
                                    0
                                    • Z Offline
                                      Z Offline
                                      zidom
                                      wrote on last edited by
                                      #18

                                      Thanks a lot for your helps
                                      but still same error i am confused

                                      1 Reply Last reply
                                      0
                                      • Z Offline
                                        Z Offline
                                        zidom
                                        wrote on last edited by
                                        #19

                                        Hi
                                        i made some changes
                                        then i could connect to database
                                        @#include <QCoreApplication>
                                        #include <QtSql>
                                        #include <QDebug>
                                        int main(int argc, char *argv[])
                                        {
                                        QCoreApplication a(argc, argv);
                                        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
                                        db.setHostName("LOCALHOST\SQLEXPRESS");
                                        db.setDatabaseName("mydsn32");
                                        if(db.open())
                                        {
                                        qDebug() << "Opened";
                                        db.close();
                                        }
                                        else
                                        {
                                        qDebug() <<"Error = "<<db.lastError();
                                        }
                                        return a.exec();
                                        }
                                        @
                                        i made a dsn and i used QSQLITE but i can not still use QODBC but its better than nothing

                                        1 Reply Last reply
                                        0
                                        • T Offline
                                          T Offline
                                          terenty
                                          wrote on last edited by
                                          #20

                                          Theres probably some issues with ODBC drivers on your OS

                                          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