Page 1 of 1

Lost connection to MySQL server during query

Posted: Wed 13 Jan 2016 23:57
by kneighbour
I am using UniDac 5.5.12 in Delphi XE7. Most of my code uses Firebird, and that seems ok. With one task I need to connect to a remote MySQL DB via tunnelling. This works, but I frequently get an error
"Lost connection to MySQL server during query".

I have tried to use the OnConnectionLost event to try a reconnection, but this event is never triggered (reading this forum, I understand why, I think).

Is there anyway to stop/hide these errors, and to get the thing to try a reconnection?

BTW - I can use other tools (ie Navicat, etc) to connect and operate on the MySQL database with no problems. Not sure why this connection is dropping out in the first place as I don't think it should.

Re: Lost connection to MySQL server during query

Posted: Thu 14 Jan 2016 14:39
by ViktorV
The MySQL server connection loss may be due to a little value of the wait_timeout MySQL system variable.
Try to set the value of the wait_timeout MySQL system variable to 31536000.
Also, MySQL server connection loss when inserting large data to MySQL server can be due to the server settings. To load big data, you should increase the value of the max_allowed_packet server variable in the my.ini file and restart your server.
To load large data, modify the max_allowed_packet server variable in the .ini file and restart the server.
For example:
max_allowed_packet = 16M
You can find more information 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 resume lost connection, you should use the TUniConnection.OnConnectionLost event handler. The OnConnectionLost event handler is used to process fatal errors and perform failover. To make the OnConnectionLost event handler work, you should set the TUniConnection.Options.LocalFailover property to True. Note that to use the OnConnectionLost event handler, you should add the MemData unit to the USES clause of your unit. Here is an example of using the OnConnectionLost event handler:

Code: Select all

procedure TForm.Button1Click(Sender: TObject);
begin
  UniConnection.Options.LocalFailover := True;
  UniConnection.Open;
end;

procedure TForm.UniConnectionConnectionLost(Sender: TObject;
  Component: TComponent; ConnLostCause: TConnLostCause;
  var RetryMode: TRetryMode);
begin
  RetryMode := rmReconnectExecute;
end;
In this case, if connection was lost, UniDAC will try to reconnect and reexecute the abortive operation. For more information, please read the UniDAC documentation: https://www.devart.com/unidac/docs/?dev ... onlost.htm

Re: Lost connection to MySQL server during query

Posted: Thu 14 Jan 2016 22:51
by kneighbour
Thanks! Very useful information.

Re: Lost connection to MySQL server during query

Posted: Fri 15 Jan 2016 09:53
by ViktorV
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.