0

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.

Laars
  • 3
  • 1

1 Answers1

0

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.

CmdrMoozy
  • 3,870
  • 3
  • 19
  • 31
  • Looks like to me the dsn inside from qt will only work with QODBC, thanks even if the dsn has the name of the db it wont work with other driver like QPSQL – Laars Jan 27 '14 at 12:44