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程序在win7 win8 win10下自动请求以管理员身份运行

Delphi 使format输出百分号 %

Delphi copy 从字符串中复制指定范围中的字符

Delphi 命令行程序调用单元函数

Delphi 记录类型- 结构指针

Delphi linklabel1 用法

Delphi 取键盘值

Delphi 在单独线程中运行窗体

Delphi 返回整数的四种情况

Delphi 多种编码转换

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



打赏

取消

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

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

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

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

评论

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