views:

70

answers:

1

Here my code snippet:

query.next();
qDebug()<<query.lastError();
qlonglong res=query.value(0).toLongLong();
qDebug()<<query.lastError();

and the corresponding log I have:

Debug: QSqlError(2006, "QMYSQL: Unable to execute query", "MySQL server has gone away") 
Warning: QSqlQuery::value: not positioned on a valid record
Debug: QSqlError(2006, "QMYSQL: Unable to execute query", "MySQL server has gone away")

Normally my program works just fine (it works on a server and accepts connections from clients), but every morning when I tried to connect it, I'm getting messages above.

What can be the problem with MySQL server?

Thanks.

+1  A: 

From the MySQL Manual:

The most common reason for the MySQL server has gone away error is that the server timed out and closed the connection.

...

By default, the server closes the connection after eight hours if nothing has happened. You can change the time limit by setting the wait_timeout variable when you start mysqld.

...

If you have a script, you just have to issue the query again for the client to do an automatic reconnection. This assumes that you have automatic reconnection in the client enabled (which is the default for the mysql command-line client).

See this manual page for more details on this error.

Alexander Konstantinov