On a TMS XData REST Server on Windows using Mysql ,I am seeing this error.
conFD: TFDPhysMySQLConnection: . MySQL server has gone away [errno=2006, sqlstate=“HY000”]
It happens after some inactivity. I am guessing that 8 hours may have passed and Mysql has disconnected to save resources. Its the only task running that uses Mysql, so resources are not an issue.
I could increase this period, but its will still happen
I could keep executing some nonsensical query periodically
I am not using TMS, but for MySQL/MariaDB/FireDAC projects I use something like this timer event handler on a long duration timer:
procedure TdmPrim.DoDBPing;
begin
{ TODO 1 -oKevin -cCode Marker : Don't do ping if we are debugging (it messes up logging and Wireshark) }
if DebugHook = 0 then begin
if DBConnectionApp.Connected then
DBConnectionApp.Ping;
LastDBPing := Now;
end;
end;
DBConnectionApp is a standard FireDAC TFDConnection.
Pinging the connection resets the timeout timer and keeps the connection open.
Cary Jensen’s book “Delphi in depth: FireDAC” (ISBN-13: 978-1546391272) is a good reference for novice FireDAC developers. I bought my copy on Amazon.
It is a bit dated (way behind in FireDAC versions), and uses a deprecated database engine in the examples, but it will generally get you going in the right direction.
My guess is that AutoReconnect will try to recover your connection after you lose it. Ping will keep the connection open proactively.