Solved

Delphi Connection Failure.  How to stop message?

Posted on 2007-03-26
3
1,931 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 18796396
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
ID: 18798507
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
ID: 18798615
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Configuring network clients can be a chore, especially if there are a large number of them or a lot of itinerant users.  DHCP dynamically manages this process, much to the relief of users and administrators alike!

710 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