Delphi: FireDac Connection blocks application

I am working on an application with a login form at startup.

Until the user writes in the login information, I would like to connect seamlessly to the SQL server.

The problem is that when I have a slow connection or the wrong path to the server, the application is looking for a server or trying to connect, and at this time the application does not respond.

To connect, I use this procedure:

//-- SQL connect --//
procedure TSql.Connect;
var
  DriverId: String;
  i: Byte;
begin
  try
    Screen.Cursor:=crAppStart;

    //connection DriverName
    DriverId:=Server[FServerType].DriverId;
    FConnection.DriverName:=DriverId;

    //connection Params
    FConnection.Params.Clear;
    FConnection.Params.Add('DriverID='+DriverId); //mandatory
    if FConnString.Count>0 then
       for i := 0 to FConnString.Count-1 do FConnection.Params.Add(FConnString.Strings[i]);

    try
      FConnection.Open;
      FQuery.Connection:=FConnection;
    except
      on E : Exception do ShowError(_('Connection could not be established!'),E);
    end;
  finally
    Screen.Cursor:=crdefault;
  end;
end;

Please help me with some suggestion on how this can be done. I read about threads and Application.ProcessMessages, but I was not able to get it to work smoothly.

+4
source share
1 answer

, , , , simillar-

+2

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


All Articles