Any progress on this one? After many tries I finally got the drivers working and now My code looks like this:
db.setHostName("127.0.0.1");
db.setDatabaseName("dbname");
db.setPort(1521);
db.setUserName("user");
db.setPassword("pass");
{
// This happens if the driver is not available
qFatal("No driver!");
}
else if(!db.open())
{
// The drivers work but the connection cannot be opened, print out why.
}
else
{
// Everything works, maybe.
qDebug() << "Connection open!";
}
db.close();
QSqlDatabase db = QSqlDatabase::addDatabase("QOCI");
db.setHostName("127.0.0.1");
db.setDatabaseName("dbname");
db.setPort(1521);
db.setUserName("user");
db.setPassword("pass");
if(!QSqlDatabase::isDriverAvailable("QOCI"))
{
// This happens if the driver is not available
qFatal("No driver!");
}
else if(!db.open())
{
// The drivers work but the connection cannot be opened, print out why.
QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
}
else
{
// Everything works, maybe.
qDebug() << "Connection open!";
}
db.close();
To copy to clipboard, switch view to plain text mode
And my tnsnames.ora looks like this:
MYDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = dbname)
)
)
MYDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = dbname)
)
)
To copy to clipboard, switch view to plain text mode
I can connect to database with the Oracle client but I am unable to do so with Qt. The host ip is something else than 127.0.0.1 in this case.
With the code above I get (through line 14) ORA-12505 error:
"TNS:listener does not currently know of SID given in connect descriptor"
However, if I swap the parametres on lines 2 and 3 I get ORA-12545:
"Connect failed because target host or object does not exist"
I've understood that the db.setHostName has nothing to do with the connection, it is just to identify the connection within Qt, am I right?
What am I doing wrong here? Please someone spell it out for me.
Bookmarks