Results 1 to 14 of 14

Thread: DB Connection Problem

  1. #1
    Join Date
    Jun 2008
    Location
    Republic of Korea
    Posts
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default DB Connection Problem

    i had this Problem, DB Connection fail!

    O.S :Windows_XP
    tool :Qt_Program(Ver. 4.3.3) installed on VisualStudio 2005
    DataBase : Oracle 10g

    I want to Connect DataBase , this is my source code

    frist, i added Qt Module(Sql)

    Qt Code:
    1. #include <QtSql>
    2. #include <QSqlDatabase>
    3. #include <QSqlQuery>
    4. #include <QSqlQueryModel>
    5.  
    6. db = QSqlDatabase::addDatabase("QOCI");
    7. db.setHostName("192.168.1.223");
    8. db.setDatabaseName("SSS");
    9. db.setPort(1521);
    10. db.setUserName("kkkk");
    11. db.setPassword("1111");
    12. bool ok = db.open();
    To copy to clipboard, switch view to plain text mode 
    and....... This defined tnsname.ora file
    Qt Code:
    1. SSS =
    2. (DESCRIPTION =
    3. (ADDRESS_LIST =
    4. (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.223)(PORT = 1521))
    5. )
    6. (CONNECT_DATA =
    7. (SERVICE_NAME = SSS)
    8. )
    9. )
    To copy to clipboard, switch view to plain text mode 

    compile Result : No error , but ok's value is false!

    so... what's is the problem?
    Last edited by jpn; 27th June 2008 at 22:46. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DB Connection Problem

    A simple question:

    Are you sure that OCI Driver is correctly loaded?

    try with
    Qt Code:
    1. if(!QSqlDatabaseisDriverAvailable("QOCI"))
    2. {
    3. qFatal("Driver not loaded");
    4. }
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Aug 2008
    Location
    Karjaland
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DB Connection Problem

    Ktmdwn, have you ever solve your problem? I have just like this problem.

    Please, give your advise.

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: DB Connection Problem

    database name should looks like (in you case)
    "(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.223)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = SSS)))"

  5. #5
    Join Date
    Aug 2008
    Location
    Karjaland
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DB Connection Problem

    Quote Originally Posted by spirit View Post
    database name should looks like (in you case)
    Spirit, as far as i can understand it's contest of tnsname.ora file?

    Where i can find it? Thanks.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: DB Connection Problem

    ORACLE_HOME\NETWORK\ADMIN\ -- under windows.
    as I know under Linux the same path, but check

  7. #7
    Join Date
    Aug 2008
    Location
    Karjaland
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: DB Connection Problem

    Quote Originally Posted by spirit View Post
    ORACLE_HOME\NETWORK\ADMIN\ -- under windows.
    as I know under Linux the same path, but check
    Spirit, thanks.

    Unfortunately, i cann't find this file =(. As far as i've understood this file is part of oracle server. But I have just Oracle Client (Oracle Client 10g Express Edition) and server is located in local netwoork.
    What should i do for connect?

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: DB Connection Problem

    if you know ip-address of the server then you should ask the one who manage the server service name.

  9. #9
    Join Date
    Jul 2010
    Location
    Tampere, Finland
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: DB Connection Problem

    Any progress on this one? After many tries I finally got the drivers working and now My code looks like this:

    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QOCI");
    2. db.setHostName("127.0.0.1");
    3. db.setDatabaseName("dbname");
    4. db.setPort(1521);
    5. db.setUserName("user");
    6. db.setPassword("pass");
    7.  
    8. if(!QSqlDatabase::isDriverAvailable("QOCI"))
    9. {
    10. // This happens if the driver is not available
    11. qFatal("No driver!");
    12. }
    13. else if(!db.open())
    14. {
    15. // The drivers work but the connection cannot be opened, print out why.
    16. QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
    17. }
    18. else
    19. {
    20. // Everything works, maybe.
    21. qDebug() << "Connection open!";
    22. }
    23. db.close();
    To copy to clipboard, switch view to plain text mode 

    And my tnsnames.ora looks like this:

    Qt Code:
    1. MYDB =
    2. (DESCRIPTION =
    3. (ADDRESS_LIST =
    4. (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    5. )
    6. (CONNECT_DATA =
    7. (SERVICE_NAME = dbname)
    8. )
    9. )
    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.
    Last edited by Ionwind; 2nd August 2010 at 11:34.

  10. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: DB Connection Problem

    try to pass this line

    1. MYDB =
    2. (DESCRIPTION =
    3. (ADDRESS_LIST =
    4. (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    5. )
    6. (CONNECT_DATA =
    7. (SERVICE_NAME = dbname)
    8. )
    9. )
    into QSqlDatabase::setDatabaseName.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  11. #11
    Join Date
    Jul 2010
    Location
    Tampere, Finland
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: DB Connection Problem

    I tried that too, it gives me different error: ORA-12145:
    "TNS:could not resolve the connect identifier specified"
    Any other ideas? : /

  12. #12
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: DB Connection Problem

    where did you try to set up connection: on linux or windows? did you try to connect to a database using the SqlBrowser from Qt demos directory?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  13. #13
    Join Date
    Jul 2010
    Location
    Tampere, Finland
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: DB Connection Problem

    I'm running on 32-bit Win XP, Qt Creator 2.0.0, on Qt 4.7.0. I've never tried out the SqlBrowser on the demos. Now when I tried it, I just got a message a through the application output after building: "The process could not be started!"

  14. #14
    Join Date
    Jul 2010
    Location
    Tampere, Finland
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Lightbulb Re: DB Connection Problem

    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:
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QOCI");
    2. db.setHostName("127.0.0.1"); // The TCP/IP of the host goes here
    3. db.setDatabaseName("foo"); // As suggested, the database name goes here :P
    4. db.setPort(1521);
    5. db.setUserName("user");
    6. db.setPassword("pass");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 10:22
  2. connection Problem
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2007, 17:59
  3. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  4. Signal-slots connection problem.
    By impeteperry in forum Qt Tools
    Replies: 26
    Last Post: 23rd January 2007, 14:33
  5. connection problem
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 7th July 2006, 22:14

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.