Solved

How do I reconnect ADOConnection or ADODataset after connection failure

Posted on 2007-04-07
17
4,723 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
Comment Utility
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
Comment Utility
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
Comment Utility
What settings are you refering to the ODBC setting? Please provide how the setting should be. or example of the settings. xr1140
0
 

Author Comment

by:erwingosepa
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
can give me workable example in delphi?
0
 
LVL 15

Expert Comment

by:mikelittlewood
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:erwingosepa
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
Try this:

1.

Try

//Connection code here...

except

//Connection code here again

end;

Just an idea!


0
 

Expert Comment

by:goldengaming
Comment Utility
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
Comment Utility
Forced accept.

Computer101
EE Admin
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now