PDA

View Full Version : Keeping the connection open



KillGabio
7th February 2012, 14:57
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.


db = QSqlDatabase::addDatabase ("QOCI");
db.setDatabaseName("XE");
db.setUserName("xxxxx");
db.setPassword("xxxxxx");
db.setHostName("127.0.0.1");
db.setPort(1521);
if(db.open ()){
model = new QSqlQueryModel ();

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....

KillGabio
8th February 2012, 16:59
any ideas??

wysota
8th February 2012, 17:07
Why do you need to reopen the connection?

KillGabio
8th February 2012, 17:56
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...

wysota
8th February 2012, 18:59
Maybe there is a connection timeout set on the database server?

KillGabio
8th February 2012, 20:16
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 :)

wysota
8th February 2012, 20:28
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.