Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I reconnect ADOConnection or ADODataset after connection failure

Posted on 2007-04-07
17
Medium Priority
?
5,235 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 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