Qt ODBC data source not found
Hello all,
Currently i am working on a project in which i have to connect MySQL database through ODBC.
Operating system : CentOS
the problem i am facing is, whenever i execute the aplication it says
[unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unable to connect
Code:
database_manager_
= QSqlDatabase::addDatabase("QODBC3",
"test_qt");
database_manager_.setDatabaseName("Server=localhost;Database=test_qt;user=karan;password=karan;");
database_manager_.setHostName("localhost");
database_manager_.setUserName("karan");
database_manager_.setPassword("karan");
searched a lot on google but not found any successfull solution.
Please help..
Re: Qt ODBC data source not found
On Linux you should use the MySql plugin not ODBC.
If you must use ODBC for some odd reason then you need to provide a valid ODBC DSN in the call to setDatabaseName(), which is the error message you are getting. You define a DSN using the tools provided with unixODBC. Of course you also need a suitable MySQL ODBDC driver.
Re: Qt ODBC data source not found
I have changed my DSN and now another problem occured:
Code:
database_manager_
= QSqlDatabase::addDatabase("QODBC3",
"test_qt");
database_manager_.setDatabaseName("MySQL_Test");
// database_manager_.setDatabaseName("Driver={MySQL_Test};USER=karan;Password=karan;SERVER=localhost;");
database_manager_.setHostName("localhost");
database_manager_.setUserName("karan");
database_manager_.setPassword("karan");
when i execute the above code it gives me :
Code:
("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3")
Driver available : true
Database opened successfully
"MySQL_Test"
createEmployeeTable : false
getProfileRecords EXEC : false
Hopefully that means it connects to the DSN and database got opened but why it gives error as "database not open" when i want to create a table.
what is the problem here please help...
Added after 1 32 minutes:
:P
I got the solution... :
Just missed to pass the QSqlDatabase object in QSqlQuery ...
Code:
query.exec("SELECT * FROM table_name");