Skip to content
  • 0 Votes
    24 Posts
    4k Views
    A

    @JSher said in Building QT with "windeployqt": not connect to database (ODBC):

    Its connecting to an OBDC entry in windows by the looks of it. I do not use ODBC much but the way I understand it is you have to make the entry on each machine....Thats why I use the standard mysql connector, then you do not. I could be off:)

    Ok thank you very much!!! I evaluate the transition to the mysql connector

  • 0 Votes
    4 Posts
    2k Views
    Andy314A

    @Ovidiu_GCO
    {SQL Server Native Client 17.0 };
    What is with the blank in front of "}"

  • 0 Votes
    17 Posts
    4k Views
    A

    @SGaist I did it this way for reading return params:

    Query.nextResult(); // after reading table values //Get Return Parameter for (int i=0; i<CountReturnParam; i++) { qDebug() << QString("Returnparam %1 = %2") .arg(i).arg(Query.boundValue(i).toString()); }
  • 0 Votes
    17 Posts
    10k Views
    jwernernyJ

    I've uncovered the same issue with QSqlQueryModel using the Windows QODBC database engine connected to MS SQL Server, and have been do some digging. Hopefully this will help others experiencing this issue.

    There are a couple of different things happening here.

    First, QSqlQueryModel does not support forward only queries. If you try to use a forward only query, QSqlQueryModel::lastError() will return "Forward-only queries cannot be used in a data model".

    That seems clear, but does not explain the situation when the forward only is left in its default false state or explicitly set in code. During my exploration of the issue, I would notice that even though I called QSqlQuery::setForwardOnly(false), a call to QSqlQuery::isForwardOnly() made after the query was executed would show forward only set to true, something I did not understand.

    Then I read the Qt documentation for setForwardOnly:

    Setting forward only to false is a suggestion to the database engine, which has the final say on whether a result set is forward only or scrollable. isForwardOnly() will always return the correct status of the result set.

    The database engine has the final say whether or not forward only is used!

    Why was the database engine setting forward only? Qt's SQL Database Drivers documentation gives part of the answer if you know what you are looking at.

    ODBC Stored Procedure Support

    With Microsoft SQL Server the result set returned by a stored procedure that uses the return statement, or returns multiple result sets, will be accessible only if you set the query's forward only mode to forward using QSqlQuery::setForwardOnly().

    By observation, the QODBC database engine (in Qt 5.8) recognizes when more than one return set has resulted from the query, so it is automatically setting forward only to true.

    How are multiple result sets generated? I've uncovered a few ways.

    A query that has multiple select statements (e.g. select * from table1; select * from table2). Stored Procedures In particular, MS SQL Server documentation has this to say:

    SQL Server stored procedures have four mechanisms used to return data:

    Each SELECT statement in the procedure generates a result set. The procedure can return data through output parameters. A cursor output parameter can pass back a Transact-SQL server cursor. The procedure can have an integer return code.

    The first item in Microsoft's list was the key for me. When NOCOUNT is OFF, Even a simple internal variable assignment using a select (e.g. select @user = 'fred') generated a return set. Setting NOCOUNT to ON stops this behavior. From Microsoft's documentation on NOCOUNT

    SET NOCOUNT ON prevents the sending of DONE_IN_PROC messages to the client for each statement in a stored procedure. For stored procedures that contain several statements that do not return much actual data, or for procedures that contain Transact-SQL loops, setting SET NOCOUNT to ON can provide a significant performance boost, because network traffic is greatly reduced.

    The Solution for me turned out to be two things:

    Add SET NOCOUNT ON to the top of my stored procedure so that only the select statement I cared about was returned Instead of using QSqlQueryModel, manually extract the results from the query and build my own QStandardItemModel.
  • 0 Votes
    6 Posts
    2k Views
    W

    @mrjj well, thanks.
    I've tried to add #include <sqltypes.h> just in case, and voilĂ , now there are errors(C2065, C3861) inside Qt(drivers\odbc\qsql_odbc.cpp).

    Don't know if it's better, but still something.

  • 0 Votes
    10 Posts
    7k Views
    A

    @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

  • 1 Votes
    6 Posts
    2k Views
    SGaistS

    Hi,

    Did you already checked the bug report system to see if it's something known ? If not, can you open a new report with a minimal compilable example that shows this behavior ?

  • 0 Votes
    2 Posts
    1k Views
    SGaistS

    Hi,

    Looks like you've opened a x86 development command line rather than the amd64.

  • 0 Votes
    2 Posts
    1k Views
    hskoglundH

    Hi, I got the libqsqlodbc.so plugin to load successfully, I think it was last year with Qt 5.2 or 5.3, but I remember I had same kind of difficulties because the libqsqlodbc.so plugin is depending on libodbc.so being in the correct place. You could check with
    ldd libqsqlodbc.so
    to see what .so files are missing..

  • 0 Votes
    1 Posts
    921 Views
    No one has replied
  • 0 Votes
    2 Posts
    3k Views
    Kanni1303K

    My ini file content
    cat ~/.odbc.ini
    [MSSQL]
    Driver = FreeTDS
    Description = Northwind sample database
    Trace = No
    Server = 122.165.14.207
    Port = 1433
    Database = JSEB_SBM
    cat /usr/local/etc/freetds.conf
    #$Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $

    #This file is installed by FreeTDS if no file by the same
    #name is found in the installation directory.

    #For information about the layout of this file and its settings,
    #see the freetds.conf manpage "man freetds.conf".

    #Global settings are overridden by those in a database
    #server specific section
    [global]
    # TDS protocol version
    ; tds version = 4.2

    # Whether to write a TDSDUMP file for diagnostic purposes # (setting this to /tmp is insecure on a multi-user system)

    ; dump file = /tmp/freetds.log
    ; debug flags = 0xffff

    # Command and connection timeouts

    ; timeout = 10
    ; connect timeout = 10

    # If you get out-of-memory errors, it may mean that your client # is trying to allocate a huge buffer for a TEXT field. # Try setting 'text size' to a more reasonable limit text size = 64512

    #A typical Sybase server
    [egServer50]
    host = symachine.domain.com
    port = 5000
    tds version = 5.0

    #A typical Microsoft server
    [MSSQL]
    host = 122.165.14.207
    port = 1433
    tds version = 7.1
    and my Qt call
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
    db.setDatabaseName("MSSQL");
    db.setUserName("sa");
    db.setPassword("*******");
    db.setHostName("122.165.14..207");
    db.setPort(1433);