Solved

Delphi Connection Failure.  How to stop message?

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 90
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 67
Undo a Print Server Setup 5 86
Wincontrol not (correctly) drawn 15 38
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…
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!
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 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