PDA

View Full Version : Qt ODBC data source not found



karankumar1609
29th June 2013, 09:21
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



database_manager_ = QSqlDatabase::addDatabase("QODBC3", "test_qt");
database_manager_.setDatabaseName("Server=localhost;Database=test_qt;user=karan;passw ord=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..

ChrisW67
29th June 2013, 09:34
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.

karankumar1609
1st July 2013, 08:37
I have changed my DSN and now another problem occured:


database_manager_ = QSqlDatabase::addDatabase("QODBC3", "test_qt");
database_manager_.setDatabaseName("MySQL_Test");
// database_manager_.setDatabaseName("Driver={MySQL_Test};USER=karan;Password=karan;SERV ER=localhost;");
database_manager_.setHostName("localhost");
database_manager_.setUserName("karan");
database_manager_.setPassword("karan");


when i execute the above code it gives me :


("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3")
Driver available : true
Database opened successfully
"MySQL_Test"
QSqlQuery::exec: database not open
createEmployeeTable : false
QSqlQuery::exec: database not open
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 ...




QSqlQuery query(database_object);
query.exec("SELECT * FROM table_name");