Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtSql - Data source name not found..
QtWS25 Last Chance

QtSql - Data source name not found..

Scheduled Pinned Locked Moved Solved General and Desktop
qsqlerrorqodbcqsql
5 Posts 3 Posters 6.1k Views
  • 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.
  • C Offline
    C Offline
    Core2
    wrote on 14 Jul 2017, 16:32 last edited by
    #1

    Hello everyone!

    I am a new user of Qt and I am trying to connect to a MS SQL db. I am using Qt 5.9.1 and Qt Creator 4.3.1 On a Windows 10 64-bit environment.

    Currently I am trying to get the QSql Browser example to work. When I run the program and try to add a connection I select the QODBC driver, add the db name, username, pass, and hostname, and select ok. The following text is the error that is displayed:

    "An error occurred while opening the connection: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect."

    bool ok = QSqlDatabase::isDriverAvailable("QODBC");
    

    Returns true.

    In an attempt to try and figure this out and start simple I followed this guys tutorial on youtube.

    And I get the same error:
    SQL Error: "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified QODBC3: Unable to connect"

    Any help would be greatly appreciated.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Jul 2017, 20:41 last edited by
      #2

      Hi and welcome to devnet,

      Did you already saw the Qt documentation about the ODBC driver ? There is also an interesting article in the Wiki regarding ODBC handling.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • H Offline
        H Offline
        hskoglund
        wrote on 15 Jul 2017, 01:16 last edited by
        #3

        Just to add to @SGaist, before running the QSql Browser example, don't forget you need to add your db name as a User DSN in Control Panel, Administrative Tools and ODBC Data Sources (32-bit) or ... (64-bit) if you're using a 64-bit compiler.
        I.e. username and password you need to specify 2 times, first in ODBC Control Panel's User DSN and then one more time in when you run QSQl Browser.
        Also hostname in QSql browser you don't need to type in, it's done in ODBC Control Panel.
        Hope this helps!

        1 Reply Last reply
        3
        • C Offline
          C Offline
          Core2
          wrote on 17 Jul 2017, 14:11 last edited by Core2
          #4

          Thank you SGaist, and hskoglund for taking time to answer my question. SGaist, I had skimmed through the page you linked but missed this part:

           *When connecting to an ODBC datasource, you should pass the name of the ODBC datasource to the 
             QSqlDatabase::setDatabaseName() function, rather than the actual database name.*
          

          hskoglund, at the time I submitted my question to the Qt Forum I had not created a DSN data source. Soon after my post I created one but was still getting the error I posted in my original post. This morning once I read the page SGaist linked again I set the DatabaseName() to the DSN data source and everything is working now! Good to know I don't have to enter the hostname twice. I tried both cases and I was able to connect when i specified the hostname or left it blank.

          Thanks again to you both.

          Lesson learned don't skim through important documentation too quickly:)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 17 Jul 2017, 21:30 last edited by
            #5

            Great !

            Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            1/5

            14 Jul 2017, 16:32

            • Login

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