Solved

How do I reconnect ADOConnection or ADODataset after connection failure

Posted on 2007-04-07
17
4,849 Views
Last Modified: 2012-05-05
How do I reconnect ADOConnection or ADODataset after I get EOleException with Message '[Microsoft] [ODBC SQL Server Driver] Communication link failure'

try
  ADOConnection.open;
except
  ADOConnection.Close;
end;

When I reconnect, The message be rompted constanly. I have to shutdown the application completly and and start again.

0
Comment
Question by:erwingosepa
  • 4
  • 4
  • 3
  • +5
17 Comments
 
LVL 5

Expert Comment

by:xr1140
ID: 18870223
You receive that error message because the connection settings are not correctly defined, so before you  reconnect try resetting those settings.
0
 
LVL 11

Expert Comment

by:calinutz
ID: 18870393
Do you have a network problem by any chance?
I mean... your application connects to the database and sometimes you receive this error message while being connected?
Or what exactly happens?
Try
ADOCOnnection.Connected:=false;
ADOCOnnection.ConnectionString:='here place your connection string';
ADOCOnnection.Connected:=true;

Regards

0
 

Author Comment

by:erwingosepa
ID: 18870450
What settings are you refering to the ODBC setting? Please provide how the setting should be. or example of the settings. xr1140
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:erwingosepa
ID: 18870461
calinutz, my problem is to restore when the connection is broken. The network problem is initialted by myself. I wanto to restore the connection after the failure but the network connection is up but it error message is keep indicating communication failure.
0
 
LVL 5

Accepted Solution

by:
xr1140 earned 500 total points
ID: 18870624

When the ODBC application calls SQLDisconnect the first time, the connection is saved to the pool. Any subsequent SQLConnect/SQLDisconnect that matches the required condition will reuse the first connection. Connection remains in the pool depends on the timeout property of the ODBC driver. The default timeout is 60sec.


restore the network and try to reconnect after 60 sec or destroy your ConnectionObject and try again
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 18871881
How about putting a timer object onto the form and set it off when you get a disconnection error.
Let it try try and reconnect every 5 seconds or something for a maximum number of trys.
0
 

Author Comment

by:erwingosepa
ID: 18871953
can give me workable example in delphi?
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 18873775
Maybe I'm leading you down the wrong path but when you get an unwanted disconnect message, set the timer off to try and reconnect. If it fails to reconnect, set the timer off again. Set the timer to 5 secs or something

procedure TForm1.ADOConnection1Disconnect( Connection: TADOConnection;
  var EventStatus: TEventStatus);
begin
   if eventStatus in [esUnwantedEvent] then
      timer1.Enabled := true
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
   timer1.Enabled := false;
   try
      ADOConnection1.Connected := true
   except
      timer1.Enabled := true
   end;
end;
0
 

Author Comment

by:erwingosepa
ID: 18873787
mikelittlewood:

I still get this error "EOleException with Message '[Microsoft] [ODBC SQL Server Driver] Communication link failure'    ' on ADODataset which is connected to ADOConnection.
0
 
LVL 5

Expert Comment

by:xr1140
ID: 18874600

try to deactivate the connection pooling. Navigate to \HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\
driver-name\ and set the CPTimeout to a lower value (the value is in seconds)
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 18874775
hmm it must be holding something in the ADOConnection somewhere.
Instead of having the ADOConnection object on your form at design time, have you tried creating the ADOconnection object at runtime instead, freeing it when you get the problem, then recreating the entire connection object instead?
0
 
LVL 5

Expert Comment

by:xr1140
ID: 18874939

i`m sure it has to do your connection pooling feature or the ODBC driver. i think your connection string is wrong and cause that error to appear ... and because connection is kept in the pool every attempt after that has the same fate because the ODBC driver will reuse the existing connection. Therefor i suggest :

(first and foremost make sure your connection string is formed correctly then)

1. create the ADO connection at run-time and destroy/recreate when the error occur
 
or

2. disable the connection pooling feature as i`ve explained in my previous post.

or

3. try to release/recreate the ADOConnection.ConnectionObject
0
 

Expert Comment

by:se_work
ID: 19441923
Hi,

did you try to catch the error?
the try.. except ... end block doesn't trap the error.
you have to deal with; like displaying the error. in the except part.

if not the error message will be displayed by the caller of the procedure ...

Something like

  try
    ADOQuery1.open;
  except
    on E: EOLEException do
    begin
      result := false;
      showmessage ('DB Connection Error.'+E.message);
    end
  end;

May be it will help you to reconnect...
If you want no interaction, just display the E.message anywhere on your form...

best
0
 
LVL 5

Expert Comment

by:Steven-Fernandez
ID: 20189153
Try this:

1.

Try

//Connection code here...

except

//Connection code here again

end;

Just an idea!


0
 

Expert Comment

by:goldengaming
ID: 20845876
I am having the same issue. I am forcing the error as well. I started off using a BDE Stored Procedure and it tells me a similar error. I tried the ADO thinking I'd be better off seeing that there are connection options for me compared to using the storedproc from the BDE component. Has anyone come up with a final solution to this issue.
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21156542
Forced accept.

Computer101
EE Admin
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

803 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