Solved

How do I reconnect ADOConnection or ADODataset after connection failure

Posted on 2007-04-07
17
4,998 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 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