如何使用 ADT 表重试 Delphi TAdsConnection
据我所知,我的会员软件在 FormCreate 过程中使用以下代码连接到多个表:
{Open the Sessions}
Membership.LoginPrompt := False;
Membership.Username := 'ONLINE';
Membership.Password := '#######';
Membership.ConnectPath := MembershipLocation;
Membership.IsConnected := True;
PosConnection.ConnectPath := PosLocation;
PosConnection.IsConnected := True;
Bookings.ConnectPath := BookingsLocation;
Bookings.IsConnected := True;
Local.ConnectPath := LocalLocation;
Local.IsConnected := True;
// Open all the tables
for Wk1 := 0 to ComponentCount - 1 do
begin
{Skip the Tmp / New Tables}
if ((Components[Wk1] is TAdsTable) and (TAdsTable(Components[Wk1]).Name = 'NewTable')) then
Continue;
if ((Components[Wk1] is TAdsTable) and (TAdsTable(Components[Wk1]).Name = 'TmpTable')) then
Continue;
{Is it a TTable}
if Components[Wk1] is TAdsTable then
TAdsTable(Components[Wk1]).Active := True;
{Is it a TwwTable}
if Components[Wk1] is TwwTable then
TwwTable(Components[Wk1]).Active := True;
{Is it a TQuery}
if Components[Wk1] is TAdsQuery then
TAdsQuery(Components[Wk1]).Active := True;
end;
{Activate the Membership Tables. This is due to passwords}
Members.Active := True;
MemTypes.Active := True;
MembersById.Active := True;
MemBookMSys.Active := True;
{Rebuild the Secondry index on the MemBook table}
if RebuildIdx = True then
begin
MemBook.Active := False;
MemBook.Exclusive := True;
MemBook.Active := True;
// Check(DbiRegenIndexes(MemBook.Handle));
MemBook.Active := False;
MemBook.Exclusive := False;
MemBook.Active := True;
end;
{Make the Table Active}
MemBook.Active := True;
有时,当服务器尚未准备好时,连接会失败并且用户收到 Advantage 错误 7.xxx
我需要它重试连接多次,或者在经过一定时间后再次连接。
对于这种情况,是否有一种标准的错误捕获和重试连接方法?或者我应该在一段时间过去后重复该代码?
谢谢
From what I can see my Membership software connects to a number of tables using the following code in the FormCreate procedure:
{Open the Sessions}
Membership.LoginPrompt := False;
Membership.Username := 'ONLINE';
Membership.Password := '#######';
Membership.ConnectPath := MembershipLocation;
Membership.IsConnected := True;
PosConnection.ConnectPath := PosLocation;
PosConnection.IsConnected := True;
Bookings.ConnectPath := BookingsLocation;
Bookings.IsConnected := True;
Local.ConnectPath := LocalLocation;
Local.IsConnected := True;
// Open all the tables
for Wk1 := 0 to ComponentCount - 1 do
begin
{Skip the Tmp / New Tables}
if ((Components[Wk1] is TAdsTable) and (TAdsTable(Components[Wk1]).Name = 'NewTable')) then
Continue;
if ((Components[Wk1] is TAdsTable) and (TAdsTable(Components[Wk1]).Name = 'TmpTable')) then
Continue;
{Is it a TTable}
if Components[Wk1] is TAdsTable then
TAdsTable(Components[Wk1]).Active := True;
{Is it a TwwTable}
if Components[Wk1] is TwwTable then
TwwTable(Components[Wk1]).Active := True;
{Is it a TQuery}
if Components[Wk1] is TAdsQuery then
TAdsQuery(Components[Wk1]).Active := True;
end;
{Activate the Membership Tables. This is due to passwords}
Members.Active := True;
MemTypes.Active := True;
MembersById.Active := True;
MemBookMSys.Active := True;
{Rebuild the Secondry index on the MemBook table}
if RebuildIdx = True then
begin
MemBook.Active := False;
MemBook.Exclusive := True;
MemBook.Active := True;
// Check(DbiRegenIndexes(MemBook.Handle));
MemBook.Active := False;
MemBook.Exclusive := False;
MemBook.Active := True;
end;
{Make the Table Active}
MemBook.Active := True;
Occasionally when the server isn't ready yet the connection fails and the user gets an Advantage error 7.xxx
I need it to retry connection a number of times, or again after a certain amount of time has passed.
Is there a standard way of error catching and retrying connection for this scenario? Or should I simply repeat the code after a certain amount of time has passed?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用标准
try.. except
处理。然后,您的调用代码可以在循环中使用该函数,直到它返回 true 或超过尝试次数:
请注意,在 IDE 中运行时您将看到有关连接失败的异常消息,但在运行时则不会。如果您不想在 IDE 中看到它们,可以在“项目选项”对话框中关闭对 EADSDatabaseError 的处理。
You can use standard
try..except
handling.Your calling code then can use the function in a loop until it returns true, or exceeds the number of attempts:
Note that you'll see the exception message on connection failures when running in the IDE, but not at runtime. If you don't want to see them in the IDE, you can turn off handling of EADSDatabaseError in the Project Options dialog.