Installing ODBC driver on Ubuntu getting syntax error after running "make"



  • I'm trying to install ODBC driver to access a SQL Server Database.. After following the docs here and installing unixODBC from here

    after running

    cd $QTDIR/src/plugins/sqldrivers/odbc
    qmake "INCLUDEPATH+=/usr/local/unixODBC/include" "LIBS+=-L/usr/local/unixODBC/lib -lodbc"
    make
    

    I got a lot of syntax errors

    and still getting

    QSqlDatabase: QODBC driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7 
    

    when running my code..


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are likely using the wrong qmake.

    Use the full path to your Qt 5.7 qmake.



  • Hi. thanks for the welcome and answer.. i was about to install Windows tbh

    and wow. apparently that was the issue now it compiled.. after that i was getting the same error

    QSqlDatabase: QODBC driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
    

    but managed to fix it by copy and pasting the compiled "libqsqlodbc.so" file to

    /home/amir/Qt5.7.0/5.7/gcc_64/plugins/sqldrivers
    

    and

    /home/amir/Qt5.7.0/Tools/QtCreator/lib/Qt/plugins/sqldrivers
    

    but i am failing to open my connection. how can make sure it's working ?


  • Lifetime Qt Champion

    The open method returns a boolean value so you should check that and if false is returned then you should print the content returned by lastError.



  • it says

    [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found QODBC3: Unable to connect
    

  • Lifetime Qt Champion

    What is your connection string ?



  • DRIVER={SQL Server};Server=localhost\SQLEXPRESS;Database=honar;Uid=SA;Pwd=*******;

    and i'm using
    Microsoft SQL Server vNext (CTP1.1) - 14.0.100.187 (X64)
    Dec 10 2016 02:51:11
    Copyright (C) 2016 Microsoft Corporation. All rights reserved.
    on Linux (Ubuntu 16.04.1 LTS)


  • Lifetime Qt Champion

    Did you check unixODBC without the GUI ?



  • Dude you are awesome.. that error is solved but yet exist another one..

    Failed "[unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]TCP Provider: Error code 0x2AF9 [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Invalid connection string attribute QODBC3: Unable to connect"
    

    and this is the content of odbc.ini

    [ODBC Driver 13 for SQL Server]
    Description         = Microsoft ODBC Driver 13 for SQL Server
    Driver              = /opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.1.0
    Trace               = Yes
    TraceFile           = sql.log
    Database            = 
    Servername          = localhost
    UserName            = 
    Password            = 
    Port                = 1433
    Protocol            = 6.4
    ReadOnly            = No
    RowVersioning       = No
    ShowSystemTables    = No
    ShowOidColumn       = No
    FakeOidIndex        = No
    ConnSettings        =
    

    and odbcinst.ini

    [ODBC Driver 13 for SQL Server]
    Description=Microsoft ODBC Driver 13 for SQL Server
    Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.1.0
    Setup=/usr/local/lib/libodbc.so.2.0.0
    UsageCount=1
    


  • @SGaist Thanks for your help.. it's successfuly got connected finally.. i changed localhost\sqlexpress to localhost and it got connected.. what ever sqlexpress is there for. Thanks again



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