PDA

View Full Version : how to open a OCI db connection?



KillGabio
20th January 2012, 21:34
hi guys its me again, im trying to start a connection to an oracle database (11g) i have in my computer. The thing is i really dont know how to do it, even though i ve read the threads here in this forum with no luck...

here is the information i have:

7296

here is the code:


db = QSqlDatabase::addDatabase ("QOCI");
db.setDatabaseName("XE");
db.setUserName("KillGabio");
db.setPassword("killlll");
db.setHostName("global-0cbe695d");
db.setPort(1521);
if (db.open ()){
QSqlQuery query (db);
if( !query.exec("SELECT * FROM TABLE_PRODUCTOS") )
qDebug() << query.lastError();
else
qDebug( "Selected!" );
return true;}
else{
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"Llamar a Agus.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}

and finally the error i get:


NOD32 protected [MSAFD Tcpip [TCP/IP]]NOD32 protected [MSAFD Tcpip [UDP/IP]]NOD32 protected [MSAFD Tcpip [RAW/IP]]NOD32 protected [RSVP UDP Service Provider]NOD32 protected [RSVP TCP Service Provider]Selected!

i disabled nod32 but no luck i dont know what it.

Thank u all in advance and im trying to learn :D

wysota
21st January 2012, 00:10
Do you get the same message after disabling the firewall?

KillGabio
21st January 2012, 00:42
i uninstalled and disable firewall but the problem seems to be the next one:

"Unable to logon", "ORA-12505: TNS:listener does not currently know of SID given in connect descriptor
")

in the picture above i posted the names i have to connect...i mean i have the information but i dont know how to place it right

ChrisW67
21st January 2012, 02:12
im trying to start a connection to an oracle database (11g) i have in my computer.
Is global-0cbe695d your machine or a remote machine?
Can you connect to that database using Oracle command line utilities and that TNS entry? Try:


sqlplus KillGabio/killlll@XE
OR
tnsping XE
I am very Oracle rusty.

Try it without specifying the hostName() and port() and see if it picks them up from the XE TNS name.

KillGabio
21st January 2012, 02:41
hi, i ve tried what u said and it gives me the following error:

QSqlError(12154, "Unable to logon", "ORA-12154: TNS:could not resolve the connect identifier specified")

i found an answer but i cant really understand it..

I solved my problem!
I connect to the database with the client with database name bar.foo and I tried to put that as parameter to QSqlDatabase::setDatabaseName() too. The connection, however, opened when I put there just foo (as in not bar.foo.

So the right values were following:


QSqlDatabase db = QSqlDatabase::addDatabase("QOCI");
db.setHostName("127.0.0.1"); // The TCP/IP of the host goes here
db.setDatabaseName("foo"); // As suggested, the database name goes here :P
db.setPort(1521);
db.setUserName("user");
db.setPassword("pass");

global is my machine... i actually downloaded Oracle 11g Express Edition, SQL Developer to edit the database and Instant Client...the last one I really didnt understand what i have to do with it cause it has no installer.. i can access the database with SQL developer especifying the information of the picture or i can enter via explorer 127.0.0.1 and see the objects (two tables and the row i added)

i ll keep reading thanks a lot and i appreciate any help

KillGabio
21st January 2012, 18:49
SOLVED

to all who try to connect to an Oracle database created with Express Edition this is howto:


db = QSqlDatabase::addDatabase ("QOCI");
db.setDatabaseName("XE");
db.setUserName("admin");
db.setPassword("killllll");
db.setHostName("127.0.0.1");
db.setPort(1521);
if (db.open ()){
QSqlQuery query (db);
if( !query.exec("SELECT * FROM TABLE_PRODUCTOS") )
qDebug() << query.lastError();
else
qDebug( "Selected!" );
return true;}
else{
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
qDebug() << db.lastError ();
return false;
}

in the Database name goes the SID not the name you gave it to the database, for the host you can either put LOCALHOST or the TCPIP dir (127.0.0.1)
the user and pass are the ones you create at the workespace and in the setPort you indicate the listener port, i think for all Oracle servers is 1521
hope this is helpfull to someone

greetings!

thaihoangluu
23rd April 2012, 10:32
SOLVED

to all who try to connect to an Oracle database created with Express Edition this is howto:


db = QSqlDatabase::addDatabase ("QOCI");
db.setDatabaseName("XE");
db.setUserName("admin");
db.setPassword("killllll");
db.setHostName("127.0.0.1");
db.setPort(1521);
if (db.open ()){
QSqlQuery query (db);
if( !query.exec("SELECT * FROM TABLE_PRODUCTOS") )
qDebug() << query.lastError();
else
qDebug( "Selected!" );
return true;}
else{
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
qDebug() << db.lastError ();
return false;
}

in the Database name goes the SID not the name you gave it to the database, for the host you can either put LOCALHOST or the TCPIP dir (127.0.0.1)
the user and pass are the ones you create at the workespace and in the setPort you indicate the listener port, i think for all Oracle servers is 1521
hope this is helpfull to someone

greetings!
How can download OCI Driver ?
I not found link download :(
Please help me.