Home > Back-end >  Broken network database after reconnection can do it, but off the net of the database connection is
Broken network database after reconnection can do it, but off the net of the database connection is

Time:11-18

Through LisDataBaseConnected is true or false to judge whether the current database connection normal, abnormal, first reconnection,
Tried, even when connected, but the old database connection is not release, if the frequently broken network, database connection number is to day,

The function LisDataBaseConnect () : string;
The begin
Try
Try
ADOCXHLis:=TADOConnection. Create (nil);
ADOCXHLis. LoginPrompt:=false;
ADOCXHLis. The ConnectionString:='File name=. \ XHLis udl';
ADOCXHLis. Open;
LisDataBaseConnected:=true;
Except,
On E: the Exception do
The begin
LisDataBaseConnected:=false;
end;
end;
The finally
end;
end;

The function testselect (Data: string) : string;
Var
QTest: TADOQuery;
The begin
If not LisDataBaseConnected then
The begin
ADOCXHLis. Close;
LisDataBaseConnect ();

end;
Try
Try
The QTest: TADOQuery.=the Create (nil);
QTest. Connection:=ADOCXHLis;
QTest. Close;
QTest. SQL. The Clear;
QTest. SQL. The Add (' SELECT his_id FROM lis_base_data where base_data_id='+ QuotedStr (Data));
QTest. Open;
If not QTest. IsEmpty then
The begin
If not QTest. FieldByName (' his_id). IsNull then
The begin
Result:=QTest FieldByName (' his_id). AsString;
End
The else
Result:='0';
End
The else
Result:='no results;
Except,
On E: the Exception do
The begin
LisDataBaseConnected:=false;
ADOCXHLis. Close;
Result:=E.M essage.
end;
end;
The finally
QTest. Close;
QTest. Free;
end;

end;

CodePudding user response:

1. Set the timeout: ADOConnection1 ConnectionTimeout:=5;//5 seconds
2. Testing TADOConnection. State
  • Related