Subject RE: [IBO] ConnectionWasLost Property
Author Eric Tishler
I has a solution that seems to work most of the time (95%). There is, however a small window in which a connection lost immediately following a successful reconnection, seems to cause as problem. This question is still pending to the forum since last week. (#30111 submitted Monday March 15)

My solution involves created a thread which repeated attempts reconnection in the background approximate once every 15 seconds.

You should probably have a data module with IB_Connection, IB_Transaction and IB_Session set up to start with.

I first create a hook to the IB_ConnectionError event for my IB_Connection object. In this handler I test the error code that cause this handler to be invoked in the first place with:

if IB_Session.ConnectionLostErrCode(ErrCode) then
begin
// code to start thread here ...
Thread.resume;
end;

I start my thread suspended and then resume it, once the connection error is detected. There is some code I am not showing here to keep the discussion simple. However, once the thread is started I loop once every 15 seconds attempting a reconnect something like this:

While not Application.Terminated and IB_Connection.ConnectionWasLost do
begin
sleep(15000);
try
IB_Connection.Connect; // Will get a connection

If not IB_Connection.ConnectionWasLost then
begin
suspend;
end;
except
// on e: exception do
// DebugLog(E.Message);
end;
end;

Once the thread has reconnected I was told I have to release this connection and reestablish the connection in my main code (out of the thread). This is because the thread has its own instance of IB_Connection.

So, once back in the main code, and in a state where I know I can reconnect, I execute the following code:

try
IB_Connection.Connect;
IB_Connection.VerifyConnection;
DbConnectionLost := IB_Connection.ConnectionWasLost;
except
end;

(Where DbConnectionLost is one of the global Booleans I use to control the flow in my application)

The above code re-establishes the connection for the original IB_Connection object.

I know this is complicated, and it took some Windows messaging as well as some global Boolean flags, but I hope this helps ...

BTW - Helen, Jason, I invite your participation in this discussion (or anyone else in the forum who has accomplished this 100% successfully)

Eric Tishler
Software Architect
Resolute Partners, LLC
Phone: 203.271.1122
Fax: 203.271.1460
etishler@...

-----Original Message-----
From: Matt Nielsen [mailto:mnielsen@...]
Sent: Tuesday, March 23, 2004 10:05 AM
To: IBObjects@yahoogroups.com
Subject: Re: [IBO] ConnectionWasLost Property

Thanks for the info. I guess my help file is out of date.

Can someone give some help on the other part of my question. How do
I recover from an error "connection forcibly closed by the remote
host" error# 335544721 after the database has come back.

Thanks,

Matt
--- In IBObjects@yahoogroups.com, "Eric Tishler" <etishler@r...>
wrote:
> Direct from the IBO help file:
>
> Flag to indicate if a connection was lost.
> Applies to
> TIB_Connection
> Declaration
> property ConnectionWasLost: boolean;
>
> It is true only when the TIB_Connection object has lost it's
connection to the database
>
> Eric Tishler
> Software Architect
> Resolute Partners, LLC
> Phone: 203.271.1122
> Fax: 203.271.1460
> etishler@r...
>
> -----Original Message-----
> From: Matt Nielsen [mailto:mnielsen@c...]
> Sent: Monday, March 22, 2004 4:17 PM
> To: IBObjects@yahoogroups.com
> Subject: [IBO] ConnectionWasLost Property
>
> What is the ConnectionWasLost property on the Database component
> for?
>
> I have a situation where a Service Application connects to the
> database when it starts but the database server may have been re-
> booted or the database service may have re-started and I need to be
> able to recover from a "connection forcibly closed by the remote
> host" error# 335544721 in my service so that I don't have to
restart
> the service.
>
> Thanks for the help,
>
> Matt
>
>
>
>
>
______________________________________________________________________
_____
> IB Objects - direct, complete, custom connectivity to Firebird or
InterBase
> without the need for BDE, ODBC or any other layer.
>
______________________________________________________________________
_____
> http://www.ibobjects.com - your IBO community resource for Tech
Info papers,
> keyword-searchable FAQ, community code contributions and
more !
>
>
>
>
>
> Yahoo! Groups Sponsor
>
>
> ADVERTISEMENT
>
< http://rd.yahoo.com/SIG=12cr0g4cg/M=268585.4521611.5694062.1261774/D=
egroupweb/S=1705007183:HM/EXP=1080076752/A=1950447/R=0/SIG=1245hvqf1/*
http://ashnin.com/clk/muryutaitakenattogyo?YH=4521611 <http://ashnin.com/clk/muryutaitakenattogyo?YH=4521611&yhad=1950447> &yhad=1950447>
click here
>
> < http://us.adserver.yahoo.com/l?
M=268585.4521611.5694062.1261774/D=egroupweb/S=:HM/A=1950447/rand=3007
92846>
>
> _____
>
> Yahoo! Groups Links
> * To visit your group on the web, go to:
> http://groups.yahoo.com/group/IBObjects/
>
> * To unsubscribe from this group, send an email to:
> IBObjects-unsubscribe@yahoogroups.com <mailto:IBObjects-
unsubscribe@yahoogroups.com?subject=Unsubscribe>
>
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms
of < http://docs.yahoo.com/info/terms/> Service.
>
>
> [Non-text portions of this message have been removed]



___________________________________________________________________________
IB Objects - direct, complete, custom connectivity to Firebird or InterBase
without the need for BDE, ODBC or any other layer.
___________________________________________________________________________
http://www.ibobjects.com - your IBO community resource for Tech Info papers,
keyword-searchable FAQ, community code contributions and more !



_____

Yahoo! Groups Links
* To visit your group on the web, go to:
http://groups.yahoo.com/group/IBObjects/

* To unsubscribe from this group, send an email to:
IBObjects-unsubscribe@yahoogroups.com <mailto:IBObjects-unsubscribe@yahoogroups.com?subject=Unsubscribe>

* Your use of Yahoo! Groups is subject to the Yahoo! Terms of <http://docs.yahoo.com/info/terms/> Service.


[Non-text portions of this message have been removed]