Results 1 to 7 of 7

Thread: how to open a OCI db connection?

  1. #1
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default how to open a OCI db connection?

    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:

    problem4.jpg

    here is the code:

    Qt Code:
    1. db = QSqlDatabase::addDatabase ("QOCI");
    2. db.setDatabaseName("XE");
    3. db.setUserName("KillGabio");
    4. db.setPassword("killlll");
    5. db.setHostName("global-0cbe695d");
    6. db.setPort(1521);
    7. if (db.open ()){
    8. QSqlQuery query (db);
    9. if( !query.exec("SELECT * FROM TABLE_PRODUCTOS") )
    10. qDebug() << query.lastError();
    11. else
    12. qDebug( "Selected!" );
    13. return true;}
    14. else{
    15. QMessageBox::critical(0, qApp->tr("Cannot open database"),
    16. qApp->tr("Unable to establish a database connection.\n"
    17. "Llamar a Agus.\n\n"
    18. "Click Cancel to exit."), QMessageBox::Cancel);
    19. return false;
    20. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by KillGabio; 21st January 2012 at 01:31.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how to open a OCI db connection?

    Do you get the same message after disabling the firewall?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to open a OCI db connection?

    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

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how to open a OCI db connection?

    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:
    Qt Code:
    1. sqlplus KillGabio/killlll@XE
    2. OR
    3. tnsping XE
    To copy to clipboard, switch view to plain text mode 
    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.

  5. #5
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to open a OCI db connection?

    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

  6. #6
    Join Date
    Jan 2012
    Location
    Argentina
    Posts
    167
    Thanks
    33
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to open a OCI db connection?

    SOLVED

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

    Qt Code:
    1. db = QSqlDatabase::addDatabase ("QOCI");
    2. db.setDatabaseName("XE");
    3. db.setUserName("admin");
    4. db.setPassword("killllll");
    5. db.setHostName("127.0.0.1");
    6. db.setPort(1521);
    7. if (db.open ()){
    8. QSqlQuery query (db);
    9. if( !query.exec("SELECT * FROM TABLE_PRODUCTOS") )
    10. qDebug() << query.lastError();
    11. else
    12. qDebug( "Selected!" );
    13. return true;}
    14. else{
    15. QMessageBox::critical(0, qApp->tr("Cannot open database"),
    16. qApp->tr("Unable to establish a database connection.\n"
    17. "Click Cancel to exit."), QMessageBox::Cancel);
    18. qDebug() << db.lastError ();
    19. return false;
    20. }
    To copy to clipboard, switch view to plain text mode 

    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!

  7. #7
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    56
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to open a OCI db connection?

    Quote Originally Posted by KillGabio View Post
    SOLVED

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

    Qt Code:
    1. db = QSqlDatabase::addDatabase ("QOCI");
    2. db.setDatabaseName("XE");
    3. db.setUserName("admin");
    4. db.setPassword("killllll");
    5. db.setHostName("127.0.0.1");
    6. db.setPort(1521);
    7. if (db.open ()){
    8. QSqlQuery query (db);
    9. if( !query.exec("SELECT * FROM TABLE_PRODUCTOS") )
    10. qDebug() << query.lastError();
    11. else
    12. qDebug( "Selected!" );
    13. return true;}
    14. else{
    15. QMessageBox::critical(0, qApp->tr("Cannot open database"),
    16. qApp->tr("Unable to establish a database connection.\n"
    17. "Click Cancel to exit."), QMessageBox::Cancel);
    18. qDebug() << db.lastError ();
    19. return false;
    20. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Nguyá»…n LÆ°u VÅ© - Http://nguyenluuvu.com

Similar Threads

  1. Replies: 0
    Last Post: 11th November 2011, 20:18
  2. Replies: 3
    Last Post: 25th August 2010, 13:39
  3. Replies: 1
    Last Post: 2nd April 2010, 07:42
  4. connection is not open
    By emental86 in forum Qt Programming
    Replies: 3
    Last Post: 1st December 2008, 23:04
  5. How do I keep the client connection open ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 25th March 2006, 20:06

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.