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 内存管理[6]

Delphi中使用词霸2005的动态库xdictgrb.dll实现屏幕取词

Delphi 获得当前系统的tcp所有打开端口及ip地址

dll 使用 pchar 参数的小例子

Delphi c语言对比指针的用法

Delphi console 清屏代码

Delphi 隐藏任务栏程序,取消自动对齐和网格对齐

Delphi tlist性能注意事项

Delphi 在电脑屏幕上显示图片

Delphi 检测一个网络连接是否有效带超时

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



打赏

取消

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

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

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

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

评论

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