This error is returned by MySQL. A connection to MySQL server can be lost due to connection activity timeout specified in the system variable wait_timeout of MySQL server.
Also, the connection can be lost when inserting large data due to server settings.
To load big data you need to increase the server variable value max_allowed_packet in the my.ini file and restart the server.
For example:
max_allowed_packet = 16M
More details here:
http://dev.mysql.com/doc/refman/5.0/en/ ... ables.html
http://dev.mysql.com/doc/refman/5.0/en/gone-away.html
To restore a lost connection you need to use the event handler TMyConnection.OnConnectionLost. To enable the OnConnectionLost event handler set the property TMyConnection.Options.LocalFailover to True. Please note to use the OnConnectionLost handler you need to add the MemData unit to the USES section of your unit. An example of using OnConnectionLost:
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
MyConnection1.Options.LocalFailover := True;
MyConnection1.Open;
end;
procedure TForm1.MyConnection1ConnectionLost(Sender: TObject;
Component: TComponent; ConnLostCause: TConnLostCause;
var RetryMode: TRetryMode);
begin
RetryMode := rmReconnectExecute;
end;
In this case when connection is lost MyDAC will try to reconnect and restart the failed operation. Read more in MyDAC documentation:
https://www.devart.com/mydac/docs/Deva ... onLost.htm
The OnConnectionLost event occurs only when the following conditions are fulfilled:
- a fatal error occurs;
- there are no opened transactions in a connection that are not ReadOnlyReadCommitted (if connection has at least one opened transaction, which is not ReadCommitedReadOnly, FailOver does not execute. All ReadCommitedReadOnly transaction are restored with FailOver operation);
- there are no opened and non-fetched datasets;
- there are no explicitly prepared datasets or SQLs.
Please make sure that none of the conditions above is violated.
Note that MyDAC does not automatically initiate checking connection to the server. Therefore, after successfully connecting to the server if the connection to the server disconnects the TMyConnection.Connected property will be set to True and the OnConnectionLost event will not be initiated until there is an attempt to connect to the server.