PDA

View Full Version : QPSQL and failed connection



quickNitin
16th January 2007, 06:56
I am trying to open a database through Qt . Here is the code.



inline bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setHostName("localhost");
db.setDatabaseName("/home/pgdata/data1");
db.setUserName("pgdata");
db.setPassword("krajesh");

if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}



it results in the error. FATAL: coulfd't coonnect to database /home/pgdata/data1.
/home/pgdata/data1 do exists. It is a cluster of database inside it i had created one with default name pgdata. but opening it also results in same name. I can acess and query over it using psql from command prompt. Also same code with QMYSQL works well.

quickNitin

e8johan
16th January 2007, 08:07
The database name is what you specify in USE commands at the SQL prompt. What do you USE when you operate from the prompt?

quickNitin
16th January 2007, 10:01
i have used same at both places. Only difference here is i am specifying complete path.
This i have created using createdb command.

Exact error is:


FATAL: /home/pgdata/data1 doesn't exist
QPSQL :unable to connect


I am completely out of ideas what is the issue. Is there something i missed while installing Qt? This code which i am trying to compile is sample code from Qt book so i suppose it it bug free.
Anyone can list out all the possibilities causing issues?

quickNitin

wysota
16th January 2007, 11:02
But you can't specify a complete path! Maybe the code you are referring to concerns an sqlite database?

jacek
16th January 2007, 12:18
I can acess and query over it using psql from command prompt.
How do you start psql? Do you specify database name? What does \l command print?

Most likely your database is named "pgdata".