Results 1 to 7 of 7

Thread: Keeping the connection open

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

    Default Keeping the connection open

    Hi guys a have a very simple question.
    Facts are:
    I use the OCI driver to connect to my local Oracle database. Everything works fine, I can update, insert delete without any problems.

    Problem is:
    Everytime I exec/show a new Widget or Dialog I need to reopen my database connection, even though when I create it, the compiler tells me an old connection has been removed. I`ve tried passing the database point, mem direction (&) and creating a new class the initialices the db but nothing seems to work except opening the connection before I initialize the model. I think that the main problem is the QSqlQuery because if I use a simple QSqlquery i can pass the database as a constructor parameter. Sorry for my poor explanation.

    Qt Code:
    1. db = QSqlDatabase::addDatabase ("QOCI");
    2. db.setDatabaseName("XE");
    3. db.setUserName("xxxxx");
    4. db.setPassword("xxxxxx");
    5. db.setHostName("127.0.0.1");
    6. db.setPort(1521);
    7. if(db.open ()){
    8. model = new QSqlQueryModel ();
    To copy to clipboard, switch view to plain text mode 

    Thank you all in advance.

    PS: Another quick question. Is there a way to call a program to execute before I open my app? Because I want to execute the oracle .bat: StartDB.bat so that the user doesn`t have to do it manually. I know that it starts when the system boots but sometimes for performance of the machine I need to close it for example....

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

    Default Re: Keeping the connection open

    any ideas??

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

    Default Re: Keeping the connection open

    Why do you need to reopen the connection?
    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.


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

    Default Re: Keeping the connection open

    Because if I dont open it right before calling a constructor of a QSqlQueryModel () I receive errors telling me that the database is not open...

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

    Default Re: Keeping the connection open

    Maybe there is a connection timeout set on the database server?
    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.


  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: Keeping the connection open

    I`ve check that, and no, there isnt. The thing is that if I pass through parameters the DB I can actually work with a simple QSqlQuery but not with a QSqlQueryModel (), when i work with the last one I need to open the database right before it is created.

    To my PS question of the thread, do you know something about it? Thanks a lot wysota

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

    Default Re: Keeping the connection open

    PS: Another quick question. Is there a way to call a program to execute before I open my app? Because I want to execute the oracle .bat: StartDB.bat so that the user doesn`t have to do it manually. I know that it starts when the system boots but sometimes for performance of the machine I need to close it for example....
    Just start your application through a bat script.
    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.


  8. The following user says thank you to wysota for this useful post:

    KillGabio (8th February 2012)

Similar Threads

  1. how to open a OCI db connection?
    By KillGabio in forum Qt Programming
    Replies: 6
    Last Post: 23rd April 2012, 11:32
  2. Replies: 0
    Last Post: 19th August 2010, 18:07
  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.