怎样判断ado连接已经失效
怎么进行重新连接.

解决方案 »

  1.   

    用于定时测试的语句可以比较简单的,如 select count(*) from table
      

  2.   

    可以放一个timer控件,设置好定时的时间,判断数据库是否连接正常。procedure TFrom1.TimerTimer(Sender:TObject);
    var
      s:string;
    begin
       Timer.Enabled:=false;
       s:='Provider=SQLOLEDB.1;Password=LEDUser;Persist Security Info=True;User ID=LEDUser;Initial Catalog=cpinfo;';
       try
         ADOConnection1.Close;
         ADOConnection1.ConnectionString:=s;
         ADOConnection1.Open;
       except
         Label1.Caption:='连接数据库失败!30秒后重试。(请检查网络是否连接好)';
         Timer.Interval:=30000;
         Timer.Enabled:=true;
       end; 
    end;
      

  3.   

    在执行SQL语句的时候加个try..except..end,如果是连接失败,就询问要不要重连接试下,
    s:='Provider=SQLOLEDB.1;Password=LEDUser;Persist Security Info=True;User ID=LEDUser;Initial Catalog=cpinfo;';
         ADOConnection1.Close;
         ADOConnection1.ConnectionString:=s;
         ADOConnection1.Open;
      

  4.   

    你的回答还好点
    ado本身为什么没有处理断开连接呢?