PDA

View Full Version : OT : QSql - connections fail after a while.



Harvey West
18th January 2007, 18:10
My program does a lot of transactions with a mysql database over short space of time. Server/Client hosts our XP.

After a while the connections start to fail with

DB open failed: QSqlError(2003, ""QMYSQL: Unable to connect"", ""Can't connect to MySQL server on 'localhost' (10048)"")

My hunch is the QSqlDatabase::close() connections take some time to complete.
"time to live" connection close time setting may fix this. But can't find.
I've looked in Mysql global settinggs / Tcpip registrys.

Has any one seen this before and know of a fix. Don't want to keep restarting the mysql service.

wysota
19th January 2007, 09:38
Do you have to close those connections all the time? Can't you use a persistent connection?

Harvey West
19th January 2007, 10:54
Can different hosts open up more than one connection on the same port?

This was the reason why I keep closing/opening the connections - So others can access the database concurrently.

wysota
19th January 2007, 11:20
Can different hosts open up more than one connection on the same port?
If you mean the target port then yes. For example your internet browser does exactly that :)

Harvey West
19th January 2007, 12:04
I can have multiple open connections provided i'm not from the same client host.

i.e I cannot connect to database if i have a connection already opened on the client host.

wysota
19th January 2007, 12:39
Then you have the database set up very strictly. Just don't close the connection and reuse it. If you don't use multiple threads, it'll be fine. If you do use multiple threads, then simply dedicate one thread to operate on the database and pass all database requests from other threads to the dedicated one.

Harvey West
19th January 2007, 13:46
Cheers wysota. This makes much more sense now.