Results 1 to 7 of 7

Thread: how to open a OCI db connection?

Hybrid View

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

    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

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

    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!

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

    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, 19:18
  2. Replies: 3
    Last Post: 25th August 2010, 12:39
  3. Replies: 1
    Last Post: 2nd April 2010, 06:42
  4. connection is not open
    By emental86 in forum Qt Programming
    Replies: 3
    Last Post: 1st December 2008, 22:04
  5. How do I keep the client connection open ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 25th March 2006, 19: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
  •  
Qt is a trademark of The Qt Company.