Problem with DB connection [SOLVED]
-
wrote on 27 Mar 2013, 10:27 last edited by
I've been trying to connect my program to a database, unsuccessful
@#include <QCoreApplication>
#include <QtSql>
#include <QtDebug>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);// QString servername = "LOCALHOST\SQLEXPRESS";
QString servername = "LOCALHOST\MYSQL";
QString dbname = "test.dat";QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setConnectOptions(); QString dsn = QString("DRIVER=(SQL Native Client);SERVER=%1;DATABASE=%2;UID=root;PWD=root;").arg(servername).arg(dbname);
// QString dsn = QString("DRIVER=(SQL Native Client);SERVER=%1;DATABASE=%2;Trusted_Connection=Yes;").arg(servername).arg(dbname);
// db.setDatabaseName(":memory:");
db.setDatabaseName(dsn);if(db.open()) { qDebug() << "Opened!"; db.close(); } else { qDebug() << "Error: " << db.lastError().text() ; } return a.exec();
}
@The error I keep getting is "out of memory Error opening database".
I use UniServer, with Apache and MySQL.If anyone has any ideas, I'd be grateful.
Regards!
[[merged two identical posts, Tobias]]
-
wrote on 27 Mar 2013, 10:34 last edited by
You don't need to use DSN and you've to use addDatabase("QMYSQL"); .... try to read this post:
https://qt-project.org/forums/viewthread/12380 -
wrote on 27 Mar 2013, 10:40 last edited by
It worked!
Thank you very much! -
wrote on 30 Mar 2013, 22:48 last edited by
Could you please tag this thread as [SOLVED]
-
wrote on 1 Apr 2013, 07:37 last edited by
the tag was added by someone, I also updated the title.
Regards!
2/5