Solved

Delphi Connection Failure.  How to stop message?

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

Don't miss ATEN at NAB Show April 24-27!

Visit ATEN at NAB Show to learn how our "Seamlessly Entertaining" solutions deliver fast, precise video streaming without delays for the broadcasting and media environment. ATEN will showcase its 16x16 Modular Matrix Switch (VM1600) and KVM Over IP Solution (KE6900 series).

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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