Solved

Delphi Connection Failure.  How to stop message?

Posted on 2007-03-26
3
1,844 Views
Last Modified: 2013-11-23
Hi Guys,

I'm trying to trap ADO errors in Delphi 7.  If I stop my SQL server or disconnect the network cable and run a query I get the error "Connection Failure".

I would like to stop this error from being displayed to the user and handle it internally like so....

procedure TForm1.ADOConnection1ExecuteComplete(Connection: TADOConnection;
  RecordsAffected: Integer; const Error: Error;
  var EventStatus: TEventStatus; const Command: _Command;
  const Recordset: _Recordset);
begin
   If EventStatus = esErrorsOccured Then
   Begin
      ShowMessage('show custom error.');
   End;
end;



So I can trap that an error has occured but I can't stop the application showing the ADO message of "Connection Failure"

How do I stop this error showing to the user?


Thanks
0
Comment
Question by:WoodyJ007
  • 2
3 Comments
 
LVL 17

Expert Comment

by:mokule
Comment Utility
Have You tried such a construction while establishing connection?

  try
    ADOConnection1.Connected := True;
    ADOQuery1.Active := True;
  except
    on E: exception do ShowMessage('Fatal error: ' + E.Message);
    end;

In place of ShowMessage You can execute some other desired action.
0
 

Author Comment

by:WoodyJ007
Comment Utility
Yes that does work but I was hoping for a more centralised solution to the problem.  I'd hoped I could catch all the exceptions on the connection rather than putting exception trapping round every single query in my large project.  Is this possible?
0
 
LVL 17

Accepted Solution

by:
mokule earned 500 total points
Comment Utility
More centralized is:
- place ApplicationEvents component on a form.
- use its OnException event handler

procedure TForm1.ApplicationEvents1Exception(Sender: TObject;
  E: Exception);
begin
  ShowMessage(E.Message);
end;
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now