Page 1 of 1

How to "safely" handle mysql DB disconnection

Posted: Sun 08 Oct 2006 18:18
by swierzbicki
I have a hundred of users working remotly on a 4.1x MySQL server.
My application is opening a lot of queries. After a DB disconnection, the application is no more able to reconnect and user will get a lot of Access Violation.

Is there a way to "safely" handle mysql DB disconnection ? , to reconnect and have all queries still active

Posted: Mon 09 Oct 2006 10:25
by Antaeus
Please specify exact error message you get. Are you able to locate exact place where error is raised?

> Is there a way to "safely" handle mysql DB disconnection ? , to reconnect and have all queries still active
Now this is possible if you use ClientDataset with MyDAC (MyConnection - MyQuery - DasetProvider - ClientDataSet). But in the next version of MyDAC we add support of Failover. It will allow you to reconnect to the server without closing recordsets.

Posted: Mon 09 Oct 2006 13:41
by swierzbicki
It looks like the new myDAC version behaves better then the olds one.

Now, after the disconnect, i'm only getting this errror message :
Lost Connection to MySQL Server during query
Socket Error on write. WSAGetlastError return 10054($2746)

All Queries are then closed.

Is it possible to catch this particular exception so that I will be able to automatically close all opened forms , and disable some of my Tactions ?

FWIW I'm not using the ClientDataset (moving to such structure will impact on "curent" code ? )

Thank you

Posted: Mon 09 Oct 2006 15:28
by Antaeus
To handle lost connection try to put something like this into MyConnection.OnError event handler:

Code: Select all

uses
  ... MyCall;

...

procedure TForm.MyConnectionError(Sender: TObject; E: EDAError;
  var Fail: Boolean);
begin
  if  (E.ErrorCode = CR_CONN_HOST_ERROR) or
      (E.ErrorCode = CR_SERVER_LOST) or
      (E.ErrorCode = CR_SERVER_GONE_ERROR) or
      (E.ErrorCode = ER_SERVER_SHUTDOWN) then
    ShowMessage('Connection lost');
end;

Posted: Mon 09 Oct 2006 20:42
by swierzbicki
Thank you very much Antaeus. I'll testing this asap.

A little bit of topic but will you consider to localize the MyConsts.pas unit ? (I will help you for the French version)

Posted: Tue 10 Oct 2006 15:10
by Antaeus
Thank you for consideration. We will take up your suggestion in the future.