PDA

View Full Version : Struggling to connect to the PostgreSQL database



ayanda83
14th November 2013, 20:30
hi everyone, I have struggled for a long time with trying to connect my progam to a PostgreSQL database. At first I tried connecting my program to a mysql database but after a long time of trying to building the mysql driver i gave up and tried a different database (i.e. Postgresql) and still can't connect even with postgresql. code below.
Server_A::Server_A(QObject *parent) :
QObject(parent)
{
server = new QTcpServer(this);
// threadPool.setMaxThreadCount(5000);

QString connectionStr = "Driver={PostgreSQL};Server=127.0.0.1;Port=5432;Dat abase=AsicamtheDB;Uid=root;Pwd=ayaman;";

db = QSqlDatabase::addDatabase("QODBC");
db.setConnectOptions();
db.setDatabaseName(connectionStr);

if(db.open())
{
qDebug() << "connected to database" <<endl;
}
else
{
qDebug() << "Not connected" <<endl;
qDebug() << db.lastError() <<endl;
qDebug() << db.drivers() <<endl;
}

ayanda83
15th November 2013, 07:35
does anyone know how to resolve this

stampede
15th November 2013, 11:03
1. Can you connect with "sqlbrowser" application from Qt examples ?
2. If you are trying to connect to PostgreSQL database, try QPSQL driver:


db = QSqlDatabase::addDatabase("QPSQL");

ayanda83
15th November 2013, 11:13
I did try PQSQL but it also doesn't work.

stampede
15th November 2013, 11:17
Ok, and what about 1) ?