Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Error in opening DB using QSqlQuery
Forum Updated to NodeBB v4.3 + New Features

Error in opening DB using QSqlQuery

Scheduled Pinned Locked Moved Solved 3rd Party Software
27 Posts 4 Posters 10.6k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hskoglund
    wrote on 31 Mar 2017, 23:15 last edited by hskoglund
    #9

    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.

    M 1 Reply Last reply 31 Mar 2017, 23:21
    0
    • H hskoglund
      31 Mar 2017, 23:15

      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.

      M Offline
      M Offline
      mzimmers
      wrote on 31 Mar 2017, 23:21 last edited by
      #10

      @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?

      H 1 Reply Last reply 31 Mar 2017, 23:42
      0
      • M mzimmers
        31 Mar 2017, 23:21

        @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?

        H Offline
        H Offline
        hskoglund
        wrote on 31 Mar 2017, 23:42 last edited by
        #11

        @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"?

        M 1 Reply Last reply 31 Mar 2017, 23:45
        0
        • H hskoglund
          31 Mar 2017, 23:42

          @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"?

          M Offline
          M Offline
          mzimmers
          wrote on 31 Mar 2017, 23:45 last edited by
          #12

          @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.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hskoglund
            wrote on 31 Mar 2017, 23:49 last edited by
            #13

            Hmm, just guessing, but have you tried moving your odbc.ini to your home directory?

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hskoglund
              wrote on 31 Mar 2017, 23:53 last edited by
              #14

              Another guess: try changing the first part of your odbc.ini to:

              [ODBC Data Sources]
              MySQL-test  = MyODBC Driver DSN
              
              1 Reply Last reply
              0
              • M Offline
                M Offline
                mzimmers
                wrote on 31 Mar 2017, 23:59 last edited by
                #15

                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?

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  hskoglund
                  wrote on 1 Apr 2017, 00:07 last edited by
                  #16

                  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).

                  M 1 Reply Last reply 1 Apr 2017, 00:16
                  0
                  • H hskoglund
                    1 Apr 2017, 00:07

                    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).

                    M Offline
                    M Offline
                    mzimmers
                    wrote on 1 Apr 2017, 00:16 last edited by
                    #17

                    @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?

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      hskoglund
                      wrote on 1 Apr 2017, 00:22 last edited by
                      #18

                      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...

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mzimmers
                        wrote on 1 Apr 2017, 00:28 last edited by
                        #19

                        What file are you referencing above?

                        H 1 Reply Last reply 1 Apr 2017, 00:54
                        0
                        • H Offline
                          H Offline
                          hskoglund
                          wrote on 1 Apr 2017, 00:39 last edited by
                          #20

                          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

                          1 Reply Last reply
                          0
                          • M mzimmers
                            1 Apr 2017, 00:28

                            What file are you referencing above?

                            H Offline
                            H Offline
                            hskoglund
                            wrote on 1 Apr 2017, 00:54 last edited by
                            #21

                            @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.)

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mzimmers
                              wrote on 1 Apr 2017, 01:14 last edited by
                              #22

                              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
                              
                              1 Reply Last reply
                              0
                              • H Offline
                                H Offline
                                hskoglund
                                wrote on 1 Apr 2017, 01:25 last edited by
                                #23

                                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")?

                                M 1 Reply Last reply 1 Apr 2017, 01:58
                                1
                                • H hskoglund
                                  1 Apr 2017, 01:25

                                  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")?

                                  M Offline
                                  M Offline
                                  mzimmers
                                  wrote on 1 Apr 2017, 01:58 last edited by
                                  #24

                                  @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.

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    mzimmers
                                    wrote on 1 Apr 2017, 16:24 last edited by
                                    #25

                                    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.

                                    M 1 Reply Last reply 1 Apr 2017, 16:54
                                    0
                                    • M mzimmers
                                      1 Apr 2017, 16:24

                                      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.

                                      M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 1 Apr 2017, 16:54 last edited by
                                      #26
                                      • ..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.

                                      1 Reply Last reply
                                      3
                                      • M Offline
                                        M Offline
                                        mzimmers
                                        wrote on 2 Apr 2017, 23:43 last edited by mzimmers 4 Feb 2017, 23:44
                                        #27

                                        Well, I think I have it solved. Not sure what I did differently, but here are the relevant files:

                                        /etc/odbcinst.ini

                                        [MySQL-test]
                                        Driver=/usr/local/lib/libmyodbc5a.so
                                        Setup=/usr/local/lib/libmyodbc5s.so
                                        Description=Connector/ODBC Driver DSN
                                        FileUsage=1
                                        UsageCount=1
                                        

                                        /etc/odbc.ini

                                        [MySQL-test]
                                        Description=MySQL test database
                                        Driver=MySQL-test
                                        SERVER=127.0.0.1
                                        USER=root
                                        PASSWORD=<PASSWORD-GOES-HERE>
                                        PORT=3306
                                        DATABASE=test
                                        Option=3
                                        

                                        Notes:

                                        1. I created these files using templates with the exact same data in them, and calling "odbcinst -i -s -f odbcinst.template" and "odbcinst -i -f -f odbc.template".
                                        2. I had to put the password to my root account in my odbc.template file. Not sure I like this, but I don't know what the alternative would be.
                                        3. there is nothing in the directory /etc/ODBCDataSources, and I don't have an .odbc.ini file in my home directory.
                                        4. the two pages that helped the most are:
                                          unixodbc
                                          debian
                                          And, it works:
                                        mzimmers@debian:/etc$ isql MySQL-test
                                        +---------------------------------------+
                                        | Connected!                            |
                                        |                                       |
                                        | sql-statement                         |
                                        | help [tablename]                      |
                                        | quit                                  |
                                        |                                       |
                                        +---------------------------------------+
                                        SQL>  
                                        

                                        Thanks to everyone who helped...as I said, I'm not sure what I did between the start and the end of this, but it's working now, both with isql and my Qt example.

                                        1 Reply Last reply
                                        3

                                        18/27

                                        1 Apr 2017, 00:22

                                        • Login

                                        • Login or register to search.
                                        18 out of 27
                                        • First post
                                          18/27
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved