Database Connection on Mac
-
wrote on 29 Jul 2013, 22:34 last edited by
Hi Guys
I am trying to connect to a database on my mac but looks nothing works. I am really newbie and following documentations, tutorial.
I have setup MySQL workbench and XAMPP running on my mac but all I get is
ERROR: "[iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded QODBC3: Unable to connect"I tried to follow this:
http://qt-project.org/doc/qt-4.8/sql-connecting.html
And
http://www.youtube.com/watch?v=3XE2bKUAxfw&list=SP2D1942A4688E9D63
Am I taking a totally wrong path?
My Conde is as simple as:
@
#include <QCoreApplication>
#include <QtSql>
#include <QtDebug>
#include <QString>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString servername="localhost";
QString dbname="test";
QSqlDatabase db =QSqlDatabase::addDatabase("QODBC");
db.setHostName(servername);
db.setDatabaseName(dbname);
db.setUserName("root");
db.setPassword("");if(db.open())
qDebug()<<"Opened";else
{
qDebug()<<"ERROR: "<<db.lastError().text();
}
return a.exec();
}
@ -
wrote on 30 Jul 2013, 00:57 last edited by
Well, the error message tells you that "test" is not a data source name (DSN) known to your ODBC install. From the "documentation": http://qt-project.org/doc/qt-5.0/qtsql/sql-driver.html#qodbc for the QODBC plugin:
bq. Be aware that when connecting to an ODBC datasource you must pass in the name of the ODBC datasource to the QSqlDatabase::setDatabaseName() function rather than the actual database name.
There is a native MySQL database driver plugin that you could (should) be using instead.
-
wrote on 30 Jul 2013, 21:32 last edited by
Thank you. To me seems there is something wrong with by DB setup. In JDBC using Eclipse, we need to download a JAR file then set the path in Eclipse. Does this apply in here too?
-
wrote on 31 Jul 2013, 05:15 last edited by
I tried to follow this tutorial
http://www.youtube.com/watch?v=3XE2bKUAxfwI believe my connection string is somehow wrong. Here is what I found in SQL documentation for connection string
@QString dsn = QString("Server=127.0.0.1;Database=test;Uid=root;Pwd=");@
does it look right?
1/4