Question

I'm trying to set up dsn with qt and i cant get it to work. The dsn does work with isql. I'm using ubuntu 12.04

POSTGRES is the dsn.

connection line:

QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setHostName("localhost");
db.setDatabaseName("POSTGRES");

error: FATAL: database "POSTGRES" does not exist.

I don't understand why qt doesn't do the look up to find the database behind. i made symlink (usr/local/etc) to odbc.ini and have odbcinst.ini aswell sqli does work with POSTGRES dsn.

Perhaps where will qt look for these files? Googled for 3 days now without success I kind of gave up cant solve this thank you for any help.

Was it helpful?

Solution

I believe your problem is that you're using the wrong driver. According to the Qt documentation, you need to be using the ODBC driver for DSN files to work - for example:

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

Also note that, again according to the Qt documentation, if you're trying to pass a DSN filename to setDatabaseName, then it MUST have a ".dsn" file extension:

For the QODBC driver, the name can either be a DSN, a DSN filename (in which case the file must have a .dsn extension), or a connection string.

And, finally, it must be listed in your odbc.ini.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top