Qt-interest Archive, October 2001
Problem with Oracle Database access
Message 1 in thread
Hi,
I have been using QT3's database functions successfully with the ODBC3
driver, QODBC3, and used an ODBC to connect to an Oracle database. This
all worked. Now I'm trying to do the same using QT's Oracle driver.
Unfortunately I cannot get it to connect to the database
(QSqlDatabase::open() always fails).
I have tried setting the "HostName" (QSqlDatabase::setHostName(QString
&)) to either the actual hostname of the database, or the TS Service
name. Neither would work. The username, password and database name are
allright, since they work with ODBC.
If anyone can give me any suggestions, I would be most grateful.
Thanks in advance,
Arne Heizmann
ZN AG Bochum
Message 2 in thread
I am using QOCI driver with Oracle and it is ok .
In the examples that came with qt there is a connect example. You have to
replace in the .cpp file the constants used there with the one you use or
modify the definition file included in that file . Usually if the oracle
service is properly defined you only have to specify the name of the
service, the user name and the password.
You can also try to use sqlplus from the oracle kit or in designer try to
set up a connection .
Good luck.
At 05:20 PM 10/01/2001, you wrote:
>Hi,
>
>I have been using QT3's database functions successfully with the ODBC3
>driver, QODBC3, and used an ODBC to connect to an Oracle database. This
>all worked. Now I'm trying to do the same using QT's Oracle driver.
>Unfortunately I cannot get it to connect to the database
>(QSqlDatabase::open() always fails).
>
>I have tried setting the "HostName" (QSqlDatabase::setHostName(QString
>&)) to either the actual hostname of the database, or the TS Service
>name. Neither would work. The username, password and database name are
>allright, since they work with ODBC.
>
>If anyone can give me any suggestions, I would be most grateful.
>
>Thanks in advance,
>Arne Heizmann
>ZN AG Bochum
>
>--
>List archive and information: http://qt-interest.trolltech.com
Message 3 in thread
Hi, all.
My application is using the Qt/X11, but there is segmentation fault. I managed
to trace the place causing the fault. Below is the debugger stack output:
(gdb) bt
#0 0x40450325 in QWidget::frameSize () from /usr/lib/qt-2.2.0/lib/libqt.so.2
#1 0x4044e217 in QWidget::frameGeometry ()
from /usr/lib/qt-2.2.0/lib/libqt.so.2
#2 ......
I browse the qt source code qwidget.cpp, the "extra" and "crect" are internal
variables. Does anyone know why should the function failed? or What needs to be
done for the QWidget?
best regards
Li
Message 4 in thread
Hi,
in reference to the problems I had earlier connecting to an Oracle
database server, I think I might have found out why it can't work (or
why it can only work if your database is local). The following is part
of my adaptation of one of the example programs (\examples\sql\sqltable,
main.cpp):
QSqlDatabase * db = QSqlDatabase::addDatabase( DRIVER );
db->setDatabaseName( DATABASE );
db->setUserName( USER );
db->setPassword( PASSWORD );
db->setHostName( HOST );
if( !db->open() ){
qWarning( "Unable to open database: " + db->lastError().databaseText()
);
return 1;
}
The four commands setDatabaseName, setUserName, setPassword and
setHostName do nothing but set a member variable's value to the values
provided. In particular, setHostName sets db->d->hname.
Now look at db->open():
bool QSqlDatabase::open()
{
return d->driver->open( d->dbname,
d->uname,
d->pword,
d->hname,
d->port);
}
and db->d->driver->open():
bool QOCIDriver::open( const QString & db,
const QString & user,
const QString & password,
const QString & , // <-----------
int ) // <-----------
{
if ( isOpen() )
close();
int r = OCILogon( d->env,
d->err,
&d->svc,
(unsigned char*)user.local8Bit().data(),
user.length(),
(unsigned char*)password.local8Bit().data(),
password.length(),
(unsigned char*)db.local8Bit().data(),
db.length() );
if ( r != 0 ) {
setLastError( qMakeError("Unable to logon",
QSqlError::Connection, d ) );
return FALSE;
}
setOpen( TRUE );
return TRUE;
}
Look at the line above that I have put emphasis on. The function
entirely ignores the HostName and Port! Could it be that the driver was
never meant to be used for anything but local databases?
Greetings,
Arne
Message 5 in thread
Hi Arne,
I believe your problems stem from a configuration problem. We have no
problems connecting to Oracle databases locally or over a network.
The parameters are ignored because they are not needed when connecting
to an Oracle database. The hostname and port information are usually
stored in a configuration file (tnsnames.ora) that have to be set up
when you install the OCI client libraries. Can you please check that
this is set up properly? Can you access your Oracle database from
non-Qt applications on the same system?
Regards,
--
[ signature omitted ]