1 procedure Tf_login.Timer1Timer(Sender: TObject);
 2 function TestConnected: Boolean;
 3 var
 4   aCon: TADOConnection;
 5 begin
 6   Result := False;
 7   aCon := TADOConnection.Create(nil);
 8   try
 9     aCon.LoginPrompt := False;
10     aCon.ConnectionTimeout := 1;
11     aCon.ConnectionString := 'FILE NAME='+ExtractFilePath(ParamStr(0))+'/ConnectJYBDB.udl';
12     aCon.Provider := ExtractFilePath(ParamStr(0)) + '/ConnectJYBDB.udl';
13     try
14       aCon.Connected := True;
15       Result := True;
16     except
17       Exit;
18     end;
19   finally
20     aCon.Free;
21   end;
22 end;
23 begin
24   if not TestConnected then //使用临时对象判断数据库连接状况
25   begin
26     //ShowMessage('数据库连接失败,请检查网络设置');
27     ConJYBDB.Close;
28   end
29   else
30   begin
31     if ConJYBDB.Connected then
32     ConJYBDB.Connected := True;
33   end;
34 end;

 

posted on 2019-11-22 11:09  江渔湖  阅读(325)  评论(0)    收藏  举报