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:
procedure TSql.Connect;
var
DriverId: String;
i: Byte;
begin
try
Screen.Cursor:=crAppStart;
DriverId:=Server[FServerType].DriverId;
FConnection.DriverName:=DriverId;
FConnection.Params.Clear;
FConnection.Params.Add('DriverID='+DriverId);
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.
source
share