Solved Error in opening DB using QSqlQuery
-
@mzimmers Actually it's not Qt that picks up the MySQL .so dll, that's what unixODBC suppose to do for you (i.e. a 3-step process: Qt's odbc plugin -> unixODBC -> /usr/local/lib/libmyodbc3.so)
Perhaps unixODBC does not load the libmyodbc.3.so file correctly, does your odbc.ini specify /usr/local... or something else?
-
@hskoglund: thank you for the clarification. But where did you get the filename libmyodbc.3.so you mention above? I have no such file on my system.
I only have two ODBC configuration files on my entire system with anything in them:
root@debian:/etc# pwd /etc root@debian:/etc# ls odbc* odbc.ini odbcinst.ini root@debian:/etc# more odbc* :::::::::::::: odbc.ini :::::::::::::: [MySQL-test] Description = MySQL test database Trace = Off TraceFile = stderr Driver = MySQL SERVER = 127.0.0.1 USER = root PASSWORD = PORT = 3306 DATABASE = test :::::::::::::: odbcinst.ini :::::::::::::: ; ; odbc.ini configuration for Connector/ODBC and Connector/ODBC drivers ; [ODBC Data Sources] myodbc3 = MyODBC Driver DSN [MySQL-test] Driver = /usr/local/lib/libmyodbc5a.so Description = Connector/ODBC Driver DSN SERVER = localhost PORT = USER = root Password = Database = test OPTION = 3 SOCKET = root@debian:/etc#
-
I got the name from your link above configuration in it is an odbc.ini example file, and I know from my struggles with MSSQLServer that that
Driver= <path to dll/.so file>
line is needed, so that unixODBC can load the dll properly. -
@hskoglund said in Error in opening DB using QSqlQuery:
I got the name from your link above configuration in it is an odbc.ini example file, and I know from my struggles with MSSQLServer that that
Driver= <path to dll/.so file>
line is needed, so that unixODBC can load the dll properly.Interesting. I thought the documentation was just out of date, and that the "3" represented a version that is now 5. (The "a" refers to ANSI vs. Unicode.) Not so?
-
@mzimmers Yes you're right, it's libmyodbc5a.so now, so unixODBC should load it.
Next pain point is the [DSN] stuff, do you set QSQLDatabase's .setDatabaseName to "MySQL-test"? -
@hskoglund : yes I do:
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); db.setHostName("localhost"); db.setDatabaseName("MySQL-test"); bool ok = db.open();
And this open() produces the error that I mention above.
-
Hmm, just guessing, but have you tried moving your odbc.ini to your home directory?
-
Another guess: try changing the first part of your odbc.ini to:
[ODBC Data Sources] MySQL-test = MyODBC Driver DSN
-
Just did...same results. I also renamed it to ".odbc.ini" with the same results.
The tutorial author doesn't mention it, but the configuration instructions mention some variables:
export ODBCINI=/usr/local/etc/odbc.ini export ODBCSYSINI=/usr/local/etc
I've done this, except they point to /etc. But I'm wondering whether this is correct.
Regarding your latest suggestion, should that change be in odbc.ini or odbcinst.ini?
-
Hi, about [ODBC Data Sources] try putting those 2 lines in both files.
I've googled a bit, and https://lists.mysql.com/myodbc/6311 says that the default location for odbc.ini and odbcinst.ini is /usr/local/etc, so try putting the files there (maybe unixODBC does not see your exports).
-
@hskoglund : did the insertion of those two lines, and copied the files to /usr/local/etc. Same results.
Configuring this isn't exactly easy, is it?
-
Believe me, it's even trickier on the Mac, I had some grand plans to make my db library support Windows, Linux and Mac (that's what Qt is all about after all). But to get ODBC work on Linux took maybe 2 or 3 nights, but on the Mac; easily one week :-(
Anyway, perhaps it's time to try another .so file, that post above mentions libodbcmyS.so...
-
What file are you referencing above?
-
Hi more google tips
it mentions running odbcinst, e.g. "odbcinst -i -d -f /home/username/odbc/mysql"
I don't remember having to do that for SQLServer but perhaps MySQL requires it -
@mzimmers About libodbcmyS.so that I mentioned above, it seems for MySQL there are actually 2 kinds of .so files: one driver flavored and one setup flavored, and that libodbcmyS.so is the latter.
Also, it seems both flavors are needed to be listed in odbcinst.ini.
Sorry for the confusion. Actually that last link seems pretty helpful, not that old (only 10 years!). Also it mentions running isql to test the connection (I remember the isql program as being very helpful for my debugging.) -
OK, well I still don't have a libodbcmyS.so. I do have a libmyodbc5S.so; could this be it? And, if so, how am I supposed to list both in the obdcinst.ini file?
Am I using the isql command correctly here?
root@debian:/etc# isql MySQL-test [ISQL]ERROR: Could not SQLConnect
-
Yeah, the isql command seems right and the error message seems familiar too :-) (And the error is outside the realm of Qt)
About Qt and MySql: you do know there is a probably simpler way to connect to your MySQL db: not going through the ODBC API, but instead loading Qt's plugin for MySQL directly, by using ::addDatabase("QMYSQL")?
-
@hskoglund yeah, I've already gotten the QMYSQL plugin working. I'm working with the ODBC stuff for the sake of my education, in case my next job lands me in a Windows environment.
It's strange how all the web pages on ODBC are so old...it is considered obsolescent technology now?
Anyway, I think I'm done for the night. I'll tackle this again tomorrow. Thanks for all your help.
-
I'm going to do some clean up before I attempt more troubleshooting. I've removed the duplicates of the .ini files, so they only exist in /etc now. Also, something's wrong with my configuration:
root@debian:/# odbcinst -j unixODBC 2.3.4 DRIVERS............: /etc/odbcinst.ini/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbcinst.ini/odbc.ini FILE DATA SOURCES..: /etc/odbcinst.ini/ODBCDataSources USER DATA SOURCES..: /etc/odbc.ini SQLULEN Size.......: 8 SQLLEN Size........: 8 SQLSETPOSIROW Size.: 8
How do I delete those incorrect entries? I tried the uninstall, but that doesn't seem to work.
Thanks.
-
- ..ODBC are so old...it is considered obsolescent technology now?
No, but the web made it less important as the browsers are now the clients and they need not the virtualization/abstraction that ODBC offer since its all html/json etc so maybe its not so high profile anymore.