Solved

Delphi Connection Failure.  How to stop message?

Posted on 2007-03-26
3
1,966 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

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month3 days, 15 hours left to enroll

630 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