QODBC driver not loaded



  • 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();
    }@



  • "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".



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



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





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



  • [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.



  • 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



  • 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}



  • 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



  • 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



  • I have them except the *.exp



  • 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



  • you mean i should have those *.exp files?



  • 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?



  • it returns QSQLITE



  • 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



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



  • 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



  • Theres probably some issues with ODBC drivers on your OS



  • Now I found the time to test it on my own.
    System: Windows7, Qt SDK version 1.2.1 with Qt libraries version 4.8.1 (offline installer).

    I've created a test database on a Microsoft SQL Server Express server (which basically means that the database does not run on my development machine).
    With "C:\Windows\SysWOW64\odbcad32.exe" a user DSN was set up using "Sql Server Native Client 10.0".

    Checked connection via ODVC from comandline

    @C:\Users\username>osql -D QtODBCDSN -U qtodbclogin -P passw0rd
    1>
    @

    Ok, that works, now the Qt part.

    @
    #include <QCoreApplication>
    #include <QtSql/QSqlDatabase>
    #include <QtSql/QODBCDriver>
    #include <QtSql/QSqlError>
    #include <QDebug>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    qDebug() << QSqlDatabase::drivers();
    
    QSqlDatabase dataBase = QSqlDatabase::addDatabase("QODBC");
    // using the DSN, created with odbcad32.exe here!
    dataBase.setDatabaseName("QtODBCDSN");
    dataBase.setUserName("qtodbclogin");
    dataBase.setPassword("passw0rd");
    
    if(dataBase.open())
    {
        qDebug() << "Database is open.";
        dataBase.close();
    }
    else qDebug() << "Could not open database, error=" &lt;&lt; dataBase.lastError();
    
    return a.exec(&#41;;
    

    }
    @

    Output:
    @
    ("QSQLITE", "QODBC3", "QODBC")
    Database is open.
    @

    Maybe that helps to check, if your system is corrupt:

    @
    Directory of C:\QtSDK\Desktop\Qt\4.8.1\mingw\include\QtSql

    25.09.2012 10:48 <DIR> .
    25.09.2012 10:48 <DIR> ..
    25.09.2012 10:48 23 QDB2Driver
    25.09.2012 10:48 23 QDB2Result
    25.09.2012 10:48 25 QIBaseDriver
    25.09.2012 10:48 25 QIBaseResult
    25.09.2012 10:48 25 QMYSQLDriver
    25.09.2012 10:48 25 QMYSQLResult
    25.09.2012 10:48 23 QOCIDriver
    25.09.2012 10:48 23 QOCIResult
    25.09.2012 10:48 24 QODBCDriver
    25.09.2012 10:48 24 QODBCResult
    25.09.2012 10:48 24 QPSQLDriver
    25.09.2012 10:48 24 QPSQLResult
    25.09.2012 10:48 2.964 qsql.h
    25.09.2012 10:48 27 QSqlDatabase
    25.09.2012 10:48 5.496 qsqldatabase.h
    25.09.2012 10:48 25 QSqlDriver
    25.09.2012 10:48 6.475 qsqldriver.h
    25.09.2012 10:48 27 QSqlDriverCreator
    25.09.2012 10:48 27 QSqlDriverCreatorBase
    25.09.2012 10:48 31 QSqlDriverFactoryInterface
    25.09.2012 10:48 31 QSqlDriverPlugin
    25.09.2012 10:48 2.711 qsqldriverplugin.h
    25.09.2012 10:48 24 QSqlError
    25.09.2012 10:48 3.218 qsqlerror.h
    25.09.2012 10:48 24 QSqlField
    25.09.2012 10:48 3.742 qsqlfield.h
    25.09.2012 10:48 24 QSqlIndex
    25.09.2012 10:48 3.179 qsqlindex.h
    25.09.2012 10:48 27 QSQLite2Driver
    25.09.2012 10:48 27 QSQLite2Result
    25.09.2012 10:48 26 QSQLiteDriver
    25.09.2012 10:48 26 QSQLiteResult
    25.09.2012 10:48 24 QSqlQuery
    25.09.2012 10:48 4.206 qsqlquery.h
    25.09.2012 10:48 29 QSqlQueryModel
    25.09.2012 10:48 3.650 qsqlquerymodel.h
    25.09.2012 10:48 25 QSqlRecord
    25.09.2012 10:48 4.026 qsqlrecord.h
    25.09.2012 10:48 39 QSqlRelation
    25.09.2012 10:48 37 QSqlRelationalDelegate
    25.09.2012 10:48 4.594 qsqlrelationaldelegate.h
    25.09.2012 10:48 39 QSqlRelationalTableModel
    25.09.2012 10:48 3.923 qsqlrelationaltablemodel.h
    25.09.2012 10:48 25 QSqlResult
    25.09.2012 10:48 5.050 qsqlresult.h
    25.09.2012 10:48 29 QSqlTableModel
    25.09.2012 10:48 4.699 qsqltablemodel.h
    25.09.2012 10:48 3.868 qsql_db2.h
    25.09.2012 10:48 4.311 qsql_ibase.h
    25.09.2012 10:48 4.318 qsql_mysql.h
    25.09.2012 10:48 4.122 qsql_oci.h
    25.09.2012 10:48 4.570 qsql_odbc.h
    25.09.2012 10:48 4.666 qsql_psql.h
    25.09.2012 10:48 3.886 qsql_sqlite.h
    25.09.2012 10:48 4.025 qsql_sqlite2.h
    25.09.2012 10:48 4.023 qsql_symsql.h
    25.09.2012 10:48 4.089 qsql_tds.h
    25.09.2012 10:48 26 QSymSQLDriver
    25.09.2012 10:48 26 QSymSQLResult
    25.09.2012 10:48 23 QTDSDriver
    25.09.2012 10:48 23 QTDSResult
    25.09.2012 10:48 470 QtSql
    62 File(s) 101.260 bytes
    2 Dir(s) 32.258.682.880 bytes free

    @

    @
    Directory of C:\QtSDK\Desktop\Qt\4.8.1\mingw\plugins\sqldrivers

    25.09.2012 10:49 <DIR> .
    25.09.2012 10:49 <DIR> ..
    25.09.2012 10:49 527.360 qsqlite4.dll
    25.09.2012 10:49 1.872.165 qsqlited4.dll
    25.09.2012 10:49 163.840 qsqlodbc4.dll
    25.09.2012 10:49 997.135 qsqlodbcd4.dll
    4 File(s) 3.560.500 bytes
    2 Dir(s) 32.258.682.880 bytes free
    @



  • Hi
    thanks for pursuing my problem i have problem in first part
    bq. C:\Users\username>osql -D QtODBCDSN -U qtodbclogin -P passw0rd
    it says
    [ODBC Driver Manager] Data source name not found and no default driver
    specified



  • Ok, I assume that you inserted your own values for <DSN>, <USERNAME> and <PASSWORD> and not simply entered

    @
    osql -D QtODBCDSN -U qtodbclogin -P passw0rd
    @

    If you use
    @
    C:\Windows\SysWOW64\odbcad32.exe
    @

    again and look into your configured DSN, can you connect to your database from within the Gui (ODBC Data Source Administrator)?

    Have you got "Sql Server Configuration Manager" on our machine? The link in the startmenu goes like "C:\Windows\SysWOW64\mmc.exe /32 C:\Windows\SysWOW64\SQLServerManager10.msc"

    In the left pane there is a menu entry "Sql Server Network Configuration", open that up, click the instance name you're using and make sure that "Named Pipes" is disabled and "TCP/IP" is enabled. That often leads to "I can not connect to server...".



  • i disabled the Named Pipes it was enable and TCP/IP was enable to and in
    C:\Windows\SysWOW64\odbc32.exe my dsn name that i created before is mydsn32 but in authenticity i selected with windows NT authentication using the network login id so i dont need the password and user name then in cmd what should i use for -U and -P?



  • Omit -U and -P, use -E instead [-E = trusted connection].

    @
    C:\Users\username>osql -?
    Microsoft (R) SQL Server Command Line Tool
    Version 10.50.1600.1 NT x64
    Copyright (c) Microsoft Corporation. All rights reserved.

    Note: osql does not support all features of SQL Server 2008 R2.
    Use sqlcmd instead. See SQL Server Books Online for details.

    usage: osql [-U login id] [-P password]
    [-S server] [-H hostname] [-E trusted connection]
    [-d use database name] [-l login timeout] [-t query timeout]
    [-h headers] [-s colseparator] [-w columnwidth]
    [-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
    [-L list servers] [-c cmdend] [-D ODBC DSN name]
    [-q "cmdline query"] [-Q "cmdline query" and exit]
    [-n remove numbering] [-m errorlevel]
    [-r msgs to stderr] [-V severitylevel]
    [-i inputfile] [-o outputfile]
    [-p print statistics] [-b On error batch abort]
    [-X[1] disable commands [and exit with warning]]
    [-O use Old ISQL behavior disables the following]
    <EOF> batch processing
    Auto console width scaling
    Wide messages
    default errorlevel is -1 vs 1
    [-? show syntax summary]
    @



  • i used -E Now it says
    @
    C:\Users\Zolfaghari>osql -D mydsn32 -E
    [ODBC Driver Manager] The specified DSN contains an architecture mismatch
    between the Driver and Application
    @



  • "First hit on Google":http://msdn.microsoft.com/en-us/library/windows/desktop/ms712362(v=vs.85).aspx

    I quote

    bq. To resolve this error, use the 32-bit odbcad32.exe to configure or remove the DSN.



  • yes i read that and fixed the problem with cmd now there is no error in cmd but in qt still says the driver not found my code is same as yours except the user and pass my include and plugin folder are same to



  • And you can confirm that you compile a 32 bit program?



  • I tried both



  • For the moment I am running out of ideas, sorry.


Log in to reply
 

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