本文整理自网络,侵删。
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中使用词霸2005的动态库xdictgrb.dll实现屏幕取词
更多相关阅读请进入《Delphi》频道 >>