PDA

View Full Version : QODBC unable to connect (part 24734)



i92guboj
13th May 2016, 20:39
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:



QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={SQLServer};SERVER=<server ip>;DATABASE=<db name>;UID=<user name>;PORT=1433;PWD=<nsa level password>;");

if( !db.isValid() )
{
qDebug() << "INVALID DATABASE!";
}
else
{
qDebug() << "Database is valid :)";
}

qDebug() << "ODBC driver valid?" << db.isValid();
if( !db.open() )
{
QString error;
error = "SERVER Said: \"" + db.lastError().text();

qDebug() << error;
for( int i=0; i<db.drivers().count(); i++ )
{
qDebug() << db.drivers().at(i);
}
}


This, outputs:



Database is valid :)
ODBC driver valid? true
"SERVER Said: " ï„€ï¿½ï¿½ï¿½ï¿½ï€€ï€€ï „€î¼€ï€€ï€€ï’€ï”€ï‚ €ï¿½ï¿½ï¿½ï¿½ï€€ï„€ï€ ��� ¿½ï€ï¿½ï¿½ï¿½ï¿½ïŽ€ïƒ€ ï…€ï”€ï“€ïƒ€ïˆ€ï„€ï¿ ½ï¿½ï¿½ï¿½ï€ï‚€ï…€ï„ d
"QSQLITE"
"QSQLITE3"
"QMYSQL3"
"QMYSQL"
"QODBC3"
"QODBC"

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.

d_stranz
14th May 2016, 18:09
"SERVER Said: " ï„€ï¿½ï¿½ï¿½ï¿½ï€€ï€€ï „€î¼€ï€€ï€€ï’€ï”€ï‚ €ï¿½ï¿½ï¿½ï¿½ï€€ï„€ï€ ��� ¿½ï€ï¿½ï¿½ï¿½ï¿½ïŽ€ïƒ€ ï…€ï”€ï“€ïƒ€ïˆ€ï„€ï¿ ½ï¿½ï¿½ï¿½ï€ï‚€ï…€ï„ d

Really? I'd be hitting the gin, too.

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

ChrisW67
14th May 2016, 23:23
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.

i92guboj
16th May 2016, 17:00
Really? I'd be hitting the gin, too.

In this example (TCP/IP connection) (https://wiki.qt.io/ODBC), 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:


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


text(): " ï„€ï¿½ï¿½ï¿½ï¿½ï€€ï€€ï „€î¼€ï€€ï€€ï’€ï”€ï‚ €ï¿½ï¿½ï¿½ï¿½ï€€ï„€ï€ ��� ¿½ï€ï¿½ï¿½ï¿½ï¿½ïŽ€ïƒ€ ï…€ï”€ï“€ïƒ€ïˆ€ï„€ï¿ ½ï¿½ï¿½ï¿½ï€ï‚€ï…€ï„ d
driverText(): "QODBC3: Unable to connect"
databaseText(): " ï„€ï¿½ï¿½ï¿½ï¿½ï€€ï€€ï „€î¼€ï€€ï€€ï’€ï”€ï‚ €ï¿½ï¿½ï¿½ï¿½ï€€ï„€ï€ ��� ¿½ï€ï¿½ï¿½ï¿½ï¿½ïŽ€ïƒ€ ï…€ï”€ï“€ïƒ€ïˆ€ï„€ï¿ ½ï¿½ï¿½ï¿½ï€ï‚€ï…€ï„ d
number(): 0
drivers(): ("QSQLITE", "QSQLITE3", "QMYSQL3", "QMYSQL", "QODBC3", "QODBC", "QTDS7", "QTDS")



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.

d_stranz
17th May 2016, 01:07
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.

i92guboj
17th May 2016, 15:13
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. :)

i92guboj
19th May 2016, 20:41
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.

i92guboj
24th May 2016, 18:13
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/QTBUG-6928?jql=text%20~%20%22odbc%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 :)

jefftee
25th May 2016, 06:11
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?