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

相关阅读 >>

Delphi实现qq右下角弹出信息窗口

Delphi中write,read,writeln和readln的用法

Delphi中setlength使用

Delphi编程防止界面卡死的方法

Delphi从全路径中分离路径,有'\'

Delphi获取开机时间代码

Delphi从memo去重数据

Delphi的rtti实现对象的xml持久化

Delphi adotable1 链接mdb数据库

Delphi检查程序内存泄露 checkmem.pas

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...