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;