How to "safely" handle mysql DB disconnection

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

How to "safely" handle mysql DB disconnection

Post by swierzbicki » Sun 08 Oct 2006 18:18

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

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Mon 09 Oct 2006 10:25

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.

swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

Post by swierzbicki » Mon 09 Oct 2006 13:41

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

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Mon 09 Oct 2006 15:28

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;

swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

Post by swierzbicki » Mon 09 Oct 2006 20:42

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)

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 10 Oct 2006 15:10

Thank you for consideration. We will take up your suggestion in the future.

Post Reply