QtSql - Data source name not found..
-
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.
-
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.
-
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! -
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:)
-
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 :)