Database is Open and is Valid but Server has gone away...
-
Hi !
After some time of idle, the connection to database seems to be lost, lastError() returns "Server has gone away..." ..
I thought i could control this by checking if isOpen() is false, if so, then i could try to re-connect to DB.. but isOpen() returns true even if the DB's server has gone away...
The only becoming thing to my mind i can try is to detect the string error and check it, if it is "Server has gone away..." i reconnect to DB, but i'm pretty sure there must to be another way to check this..
Any ideas?
Thanks in advance. -
Hi !
After some time of idle, the connection to database seems to be lost, lastError() returns "Server has gone away..." ..
I thought i could control this by checking if isOpen() is false, if so, then i could try to re-connect to DB.. but isOpen() returns true even if the DB's server has gone away...
The only becoming thing to my mind i can try is to detect the string error and check it, if it is "Server has gone away..." i reconnect to DB, but i'm pretty sure there must to be another way to check this..
Any ideas?
Thanks in advance.@U7Development said in Database is Open and is Valid but Server has gone away...:
Server has gone away
See the answer at https://stackoverflow.com/a/15059387/489865. It's from 2013, but that way may be just as valid now, since there doesn't seem to be anything better. There is an unaddressed bug report https://bugreports.qt.io/browse/QTBUG-223. There is also the
MYSQL_OPT_RECONNECT
(db.setConnectOptions("MYSQL_OPT_RECONNECT=1");
) option if you are MySQL. You can also Google forqt database Server has gone away
. -
@U7Development said in Database is Open and is Valid but Server has gone away...:
Server has gone away
See the answer at https://stackoverflow.com/a/15059387/489865. It's from 2013, but that way may be just as valid now, since there doesn't seem to be anything better. There is an unaddressed bug report https://bugreports.qt.io/browse/QTBUG-223. There is also the
MYSQL_OPT_RECONNECT
(db.setConnectOptions("MYSQL_OPT_RECONNECT=1");
) option if you are MySQL. You can also Google forqt database Server has gone away
.I'm using MariaDB (MySQL) and did not know about that string.. i will try it.
MYSQL_OPT_RECONNECT (db.setConnectOptions("MYSQL_OPT_RECONNECT=1");)Thanks.
-
Hi !
After some time of idle, the connection to database seems to be lost, lastError() returns "Server has gone away..." ..
I thought i could control this by checking if isOpen() is false, if so, then i could try to re-connect to DB.. but isOpen() returns true even if the DB's server has gone away...
The only becoming thing to my mind i can try is to detect the string error and check it, if it is "Server has gone away..." i reconnect to DB, but i'm pretty sure there must to be another way to check this..
Any ideas?
Thanks in advance.@U7Development said in Database is Open and is Valid but Server has gone away...:
try is to detect the string error and check it,
In addition to @JonB suggestion to use the reconnection setting, instead of checking the string you could check the error number (less error prone...) see this post