delphi客户端自动重连功能

procedure Tf_login.Timer1Timer(Sender: TObject);
function TestConnected: Boolean;
var
aCon: TADOConnection;
begin
Result := False;
aCon := TADOConnection.Create(nil);
try
aCon.LoginPrompt := False;
aCon.ConnectionTimeout := 1;
aCon.ConnectionString := ‘FILE NAME=‘+ExtractFilePath(ParamStr(0))+‘/ConnectJYBDB.udl‘;
aCon.Provider := ExtractFilePath(ParamStr(0)) + ‘/ConnectJYBDB.udl‘;
try
aCon.Connected := True;
Result := True;
except
Exit;
end;
finally
aCon.Free;
end;
end;
begin
if not TestConnected then //使用临时对象判断数据库连接状况
begin
//ShowMessage(‘数据库连接失败,请检查网络设置‘);
ConJYBDB.Close;
end
else
begin
if ConJYBDB.Connected then
ConJYBDB.Connected := True;
end;
end;

delphi客户端自动重连功能

上一篇:C# POST/GET


下一篇:C#编程之WPF控件开发(九)