In my Datasnap client application I use 1 TSQLConnection for my methods and ProviderConnection.

The problems arise when the connection is lost. Both TSQLConnection.Connected and TSQLConnection.ConnectionState don't catch this.

When my TSQLconnection is open, but I lose internet connection, or the server stops the Datasnap client application gives lots of errors. (Server Methods or ClientDatasets)

I have created a function to manage my SQL connection for my server methods. but more problems arise when for example is close a ClientDataset that is connected through a TDSProviderConnection.

Q: How do you manage your client application to safely catch any disconnects on the TSQLconnection.
Q: How do you manage downtime, and what do you do with unsaved client state.

Reconnection after downtime is not the problem.

When calling a servermethod: This would throw exception.

tmpM:=TServerMethodsClient.Create(MYTSQLCONNECTION.dbxconnection,true);

So I wrote this next Method to obtain the TSQLCONNECTION from my datamodule with dummy method.

function TDMForm.DSConnection: TSQLConnection;
var
  tmpM:TServerMethodsClient;
begin
  result:=nil;
  if assigned(MYTSQLCONNECTION) then begin
    tmpM:=TServerMethodsClient.Create(MYTSQLCONNECTION.dbxconnection,true);
    try
      try
        tmpM.Ping;
        result:=MYTSQLCONNECTION
      except
        ReconnectForm.ShowModal; // has a reconnect button that tries to reconnect + shutdownbutton
        if ReconnectForm.modalresult=mrOK then
          result:=MYTSQLCONNECTION
        else
          MainForm.Close;
      end;
    finally
      tmpm.Free;
    end;
  end;
end;

I wrote the Method this way because only way to find out if connection is lost is through dummy method which would throw same error... then I can query for reconnect or close program.

Edit: I'm expecting some kind of

Edit
Report