Results 1 to 9 of 9

Thread: QODBC unable to connect (part 24734)

  1. #1
    Join Date
    Aug 2013
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QODBC unable to connect (part 24734)

    Hello.

    Yes, one more boring thread about QODBC failing to work.

    The problem is that this time is not a non-existing plugin, or an ABI issue, or a path spaguetti, or whatever else you might imagine. It might be an even sillier issue, who knows. Fact is that now I am at this kind of juncture where the idea of a flying laptop is starting not to seem a big drama.

    So, let's get to the point. I am trying to connect to a given database from a devil-ish variety; not that I am happy with the idea, but there's really no option about that; so far so good:

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    2. db.setDatabaseName("DRIVER={SQLServer};SERVER=<server ip>;DATABASE=<db name>;UID=<user name>;PORT=1433;PWD=<nsa level password>;");
    3.  
    4. if( !db.isValid() )
    5. {
    6. qDebug() << "INVALID DATABASE!";
    7. }
    8. else
    9. {
    10. qDebug() << "Database is valid :)";
    11. }
    12.  
    13. qDebug() << "ODBC driver valid?" << db.isValid();
    14. if( !db.open() )
    15. {
    16. QString error;
    17. error = "SERVER Said: \"" + db.lastError().text();
    18.  
    19. qDebug() << error;
    20. for( int i=0; i<db.drivers().count(); i++ )
    21. {
    22. qDebug() << db.drivers().at(i);
    23. }
    24. }
    To copy to clipboard, switch view to plain text mode 

    This, outputs:

    Qt Code:
    1. Database is valid :)
    2. ODBC driver valid? true
    3. "SERVER Said: "��������������������d
    4. "QSQLITE"
    5. "QSQLITE3"
    6. "QMYSQL3"
    7. "QMYSQL"
    8. "QODBC3"
    9. "QODBC"
    To copy to clipboard, switch view to plain text mode 
    Pretty standard stuff.

    The most interesting part is where it says crap about ubuntu and whatnot (I'm in Gentoo, I really wonder where does that come from...). Anyway, the plugin is there, I have tried to force QT_PLUGINS_PATH and run from the command line, same problem. I tried ldd on the binary, and also in the individual libqt*.so files that are involved (gui and sql, mostly), all seem sane (and Gentoo tools would detect that kind of breackage). Anyway, I even tried to rebuild qtsql (I knew it wouldn't help, but still...).

    I also tried copying the plugin folder to the build folder to no avail.

    Finally, I let you know that I can perfectly connect using the same IP and credentials from my command line, with the tds/unixodbc combo. So, it's definitely not a problem in my server.

    I am not new to qt neither to qtsql. I am no specialist, but I have found my way and built a small lot of applications during several years. Admittedly, I've been some months doing some other things, so, maybe it is something stupid I am missing here... At this point, after a couple days of frustration, I guess the best I can do is to close the lid and go for a gin, or a dozen.

    Any help is welcome.

    Thank you beforehand.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QODBC unable to connect (part 24734)

    "SERVER Said: "ï”€ïˆ€î®€î¡€î¼€î£€ïˆ ï„€ï¿½ï¿½ï¿½ï¿½ï€€ï€€ „€î¼€ï€€ï€€ï’€ï”€ï €ï¿½ï¿½ï¿½ï¿½ï€€ï„€ï ��� ï¿½ï€ï¿½ï¿½ï¿½ï¿½ïŽ€ïƒ ï…€ï”€ï“€ïƒ€ïˆ€ï„€ï ½ï¿½ï¿½ï¿½ï€ï‚€ï…€ï„ d
    Really? I'd be hitting the gin, too.

    In this example (TCP/IP connection), there is a space in "DRIVER=(SQL Server);". Don't know if it is relevant.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QODBC unable to connect (part 24734)

    What do QSqlError::serverText(), databaseText(), and number() return?

    Try removing the host, port, user name and password from the DSN and set them with the corresponding QSqlDatabase calls.

  4. #4
    Join Date
    Aug 2013
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QODBC unable to connect (part 24734)

    Quote Originally Posted by d_stranz View Post
    Really? I'd be hitting the gin, too.

    In this example (TCP/IP connection), there is a space in "DRIVER=(SQL Server);". Don't know if it is relevant.
    If I am not mistaken (and I easily could), that string should be the same that you have in your odbc.ini and freetds.conf files in between brackets. So, it's config dependant. But the examples out there are varied and there's no extensive documentation that I could find about this thing.

    I've used odbc in the past, not with qt though. My QtSql experience has always been against MySQL and sqlite, never had a problem with those.

    Thanks for the suggestions!


    Added after 7 minutes:


    Quote Originally Posted by ChrisW67 View Post
    What do QSqlError::serverText(), databaseText(), and number() return?
    Qt Code:
    1. text(): "��������������������d
    2. driverText(): "QODBC3: Unable to connect"
    3. databaseText(): "��������������������d
    4. number(): 0
    5. drivers(): ("QSQLITE", "QSQLITE3", "QMYSQL3", "QMYSQL", "QODBC3", "QODBC", "QTDS7", "QTDS")
    To copy to clipboard, switch view to plain text mode 

    Try removing the host, port, user name and password from the DSN and set them with the corresponding QSqlDatabase calls.
    I tried that, and many more things. Thanks for the suggestion though. But I think the problem is related to some obscure ODBC issue here. That output is certainly not normal, and as long as I continue to get corrupted output there, it might be indicative that something is not working well at the data source level.

    But then, there's the fact that using tsql, isql et al I can query whatever I want and everything works, so I guess it's the qt-to-odbc layer with is in fault here.

    Ugh.
    Last edited by i92guboj; 16th May 2016 at 16:24.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QODBC unable to connect (part 24734)

    This gibberish almost looks like a unicode conversion problem. According to the QString docs:

    QString stores a string of 16-bit QChars, where each QChar corresponds one Unicode 4.0 character. (Unicode characters with code values above 65535 are stored using surrogate pairs, i.e., two consecutive QChars.)
    Those sequences of 4 consecutive "question mark in a diamond" things could be single spaces, maybe? I'm wondering if maybe you have an endian problem that your command line access finesses for you.

  6. #6
    Join Date
    Aug 2013
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QODBC unable to connect (part 24734)

    Quote Originally Posted by d_stranz View Post
    This gibberish almost looks like a unicode conversion problem. According to the QString docs:



    Those sequences of 4 consecutive "question mark in a diamond" things could be single spaces, maybe? I'm wondering if maybe you have an endian problem that your command line access finesses for you.
    I think you might be hitting the nail there about endianness. I was about to blame on a strange low-level interaction between odbc and the vpn, though that shouldn't happen, of course.

    Googling a bit I discovered some endian-related issues between freetds and some sql server versions. More concretely, they mention 2008 r2, which matches mine.

    To discard that I'll have to update the server, which in turn requires some planning, backups, etc. So, this might take a few days.

    I'll keep you informed.

    Thanks for all the suggestions.

  7. #7
    Join Date
    Aug 2013
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QODBC unable to connect (part 24734)

    Just wanted to let you know that I did a ninja install of qt in the server. After building odbc, the test case launched at first attempt without changing a single line of code.

    This restricts the possibilities to either a bug in qsqlodbc in linux, a funny interaction between qsqlodbc and openvpn, or some kind of voodoo between qsqlodbc and unixodbc (unixodbc alone works just ok).

    To sort out vpn issues, I will setup a win box into the vpn and try.

    I'll keep you posted.

  8. #8
    Join Date
    Aug 2013
    Posts
    32
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QODBC unable to connect (part 24734)

    So far, qt in Windows works, and qt in Linux doesn't. VPN doesn't seem to be an issue, and I have tried the Qt installer as well to sort out some Gentoo specific problem due to my toolchain, gcc versions, etc.

    I found this:
    https://bugreports.qt.io/browse/QTBU...c%20corrupt%22

    Which might be related or not, I don't know. But as far as I am concerned, all the problem is in qsqlodbc.so.

    I will try one last thing, which is building the absolute latest qt version, and compiling against that. Seeing how recent that bug is, I think there's some chance that that will work.

    If it doesn't I will have to look for some other toolkit which is portable enough. I have some time constrains to meet and I've already lost three/four weeks trying to debug this. Not that I have spare time to do so, anyway.

    I'll let you know whether this works or not.

    Thanks everyone who tried
    Last edited by i92guboj; 24th May 2016 at 17:25.

  9. #9
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QODBC unable to connect (part 24734)

    Quote Originally Posted by i92guboj View Post
    Seeing how recent that bug is, I think there's some chance that that will work.
    That bug is from Qt 4.5.3 and was reported in December 18th, 2009 and the patch was provided December 21st, 2009. The fix should be in all Qt versions starting with 4.6.3 and beyond. What version of Qt are you using on Ubuntu?
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. Replies: 5
    Last Post: 27th January 2014, 22:22
  2. QODBC Driver - unable to bind variable
    By AlphaWolfXV in forum Qt Programming
    Replies: 0
    Last Post: 14th September 2011, 12:55
  3. Mac OS + Qt 4.6.2, QODBC3: Unable to connect
    By Royceybaby in forum Qt Programming
    Replies: 1
    Last Post: 8th May 2010, 10:15
  4. ODBC Oracle. Unable to connect to database
    By egil in forum Qt Programming
    Replies: 2
    Last Post: 17th October 2008, 13:46
  5. QODBC on Wine LINUX not connect
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2007, 13:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.