delphi adoconnection断线重连  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi adoconnection断线重连


adoconnection断线重连


uses ComObj;


procedure TForm1.ApplicationEvents1Exception(Sender: TObject; E: Exception);
var
  I: integer;
begin
  //请执行如下命令或者其他方法强制产生数据库连接断开情况,以触发如下异常。
  //net stop MsSqlServer
  //net start MsSqlServer
  if (E is EOleException) and ((E as EOleException).ErrorCode= -2147467259) then
  begin
    ADOConnection1.Connected := False;
    try
      ADOConnection1.Connected := True;
    except On E2: Exception do
    begin
      MessageDlg('重连数据库发生错误:'#13 + E2.Message, mtError, [mbOK], 0);
    end;
    end;
  end;
end;

来源https://www.cnblogs.com/hnxxcxg/p/12418507.html

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.03533411026001 seconds