Connetion error diffetent in ver 6 to ver 10 ?

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

Connetion error diffetent in ver 6 to ver 10 ?

Post by marsheng » Fri 27 Jul 2018 06:04

I have been using this code in Delphi 6 for many years.

Code: Select all

procedure TDM.RegisiterVerConnectionLost(Sender: TObject;
  Component: TComponent; ConnLostCause: TConnLostCause;
  var RetryMode: TRetryMode);
begin
      RetryMode := rmReconnectExecute;
end;
I have the same code in Delphi 10 Berlin however I get Lost Connection to MySQL after XXX number of minutes. If I ignore the error and continue, the program is fine.

So it looks like I'm getting the error message, the ConnectionLost is then triggered and it reconnects.

Is there something in 10 settings to ignore the temporary error message or something in Devart to fix this ?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Connetion error diffetent in ver 6 to ver 10 ?

Post by ViktorV » Fri 27 Jul 2018 08:31

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.

marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

Re: Connetion error diffetent in ver 6 to ver 10 ?

Post by marsheng » Fri 27 Jul 2018 11:13

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.
Yes I agree with the above. The program opens the connection correctly and displays the data. If I leave the program open for some time, the connection is lost, however in Delphi 6, the connectionlost routine would run as soon as you tried to access data and the re connection was seamless. The user never knew the connection was lost.

In 10 however, you get the message XXXX and pressing any key erases the message, triggers the reconnect routine and you can carry on working. How do I suppress the message or catch it before it is displayed to the user and do something more constructive.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Connetion error diffetent in ver 6 to ver 10 ?

Post by ViktorV » Fri 27 Jul 2018 13:16

Please indicate the exact text of the message that you receive. Also, please inform whether you get it only in development mode or not.

marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

Re: Connetion error diffetent in ver 6 to ver 10 ?

Post by marsheng » Mon 30 Jul 2018 10:30

I have tried to set Delphi to the release compile. I think I have it correct as the exe is 1/2 the size of the debug version. The error


Image

Hitting enter, clears the fault and the program continues normally. My guess is I have to change something in the compiler options, but I'm not sure what.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Connetion error diffetent in ver 6 to ver 10 ?

Post by ViktorV » Mon 30 Jul 2018 12:02

Unfortunately, we could not reproduce the issue on the latest version of UniDAC 7.3.9.
In order for us to be able to give you a detailed answer, we need a sample demonstrating the behavior you mentioned. Therefore, please, compose a full sample demonstrating the described behavior and send it to us using the contact form https://devart.com/company/contactform.html including database objects creating scripts.

Post Reply