Saving a network connection - mysql

I installed my delphi application, which I created using a button with a name Connect. As soon as I click on it, it will execute the following code:

begin
    someConnection.Connected:=true;
    somecomenziDataSet.Active:=true;
end;

Similarly, I have a button for Disconnectgoals that does the same thing, but with = false;

My problem is that the database I'm connecting to is hosted on a shared hosting account, and the variable wait_timeoutset to 60 seconds is interactive_timeoutset on mysql server , set to 30 seconds. Naturally, this disables me if I do not use my application for 60 seconds.

Is there a way to keep this connection?

The hosting company will not change the settings, so I was stuck with it.

I am using RAD Studio 10 Seattle, dbexpresscomponents TSQLConnection, and my databasemysql

Please let me know in the comments if I left all the necessary information, thanks!

+4
source share
1 answer

You can use TTimerfor periodic "ping" the database (for example, an interval of 10-20 seconds with a timeout of 60 seconds):

procedure TMyDataModule.ConnectionPingTimer(Sender: TObject);
begin
  if not MySQLConnection.InTransaction then
    MySQLConnection.Exceute('DO 0', nil); // or "SELECT 1" or whatever is cheapest
end;
+6
source

Source: https://habr.com/ru/post/1660826/


All Articles