<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Antonia,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Many thanks for your reply.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">
I'll re-code my app and do some more testing.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Richard</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On 25 August 2014 09:19, SPRL AFOR <span dir="ltr"><<a href="mailto:aforsprl@gmail.com" target="_blank">aforsprl@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<div>Le 25/08/2014 09:32, Richard Mace a
écrit :<br>
</div><div class="">
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hi all,</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br>
</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif">
I have the following code that I use to connect to a Firebird
database, which works fine, however, if the Firebird server
becomes unavailable, fIBConnection.Connected always returns
true. What's the best way of checking to make sure that the
Firebird server is still available before I attempt to connect
to the database?</div>
<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br>
</div>
<br>
</div>
</blockquote></div>
AFAIK the TIbConnection is based upon TSQLConnection itself based
upon the TDatabase component. In all this chain the Connected
property is defined in the latest component, the TDatabase. And the
Connected property has a read function wich sends a boolean variable
content (FConnected variable). That's why once the first connection
has been established with the Firebird server (whether is succeeds
or not), the connection status is kept thru all component life until
next disconnect or re-connect operation takes place.<br>
To solve the situation when the link to the databse server is broken
I rely on the transaction mechanism. In fact I always control the
transaction state allowing any query to be executed, as the Firebird
server requires that any database access has to be done under the
control of a transaction. This means thar when the
MyTrans.StartTransaction fails I know (most of the times) that the
link to the FB server is broken (omitting programmatic errors which
can be controlled or checkced in another way). This does not protect
your code from a connection exception between two consecutive
database access (two consecutive calls to the fbclient library
anyway). When I need a fine tuned control over a database access,
after a initial MyDB.Connected := True, I always use the same
sequence:<br>
<br>
try<br>
MyDatabase.Connedted := True;<br>
except<br>
on ...(exception process) do ... connection fault<br>
end<br>
[...] prepare data for the database <br>
try<br>
MyTransaction;StartTransaction<br>
try<br>
do whatever has to be done with the database<br>
finally<br>
MyTransaction.Commit<br>
end<br>
except<br>
do whatever needed when the exception rises: check whether
its is an ordinary exception or a server link fault<br>
if MyTransaction.InTransaction then<br>
MyTransaction.RollBack;<br>
end;<br>
<br>
This sequence does not protect against the server disconnection
between two consecutive database calls. I easily can imagine that
the same process occurs with any other database server hosted in a
remote machine. Even when the database server is hosted in the same
machine of the applicaton, TCP/IP communication applies.<br>
<br>
Antonio.<br>
<br>
<br><br>
<hr style="border:none;color:#909090;background-color:#b0b0b0;min-height:1px;width:99%">
<table style="border-collapse:collapse;border:none">
<tbody><tr>
<td style="border:none;padding:0px 15px 0px 8px">
<a href="http://www.avast.com/" target="_blank">
<img border="0" src="http://static.avast.com/emails/avast-mail-stamp.png">
</a>
</td>
<td>
<p style="color:#3d4d5a;font-family:"Calibri","Verdana","Arial","Helvetica";font-size:12pt">
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection <a href="http://www.avast.com/" target="_blank">Antivirus avast!</a> est active.
</p>
</td>
</tr>
</tbody></table>
<br>
</div>
<br>--<br>
_______________________________________________<br>
Lazarus mailing list<br>
<a href="mailto:Lazarus@lists.lazarus.freepascal.org">Lazarus@lists.lazarus.freepascal.org</a><br>
<a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus" target="_blank">http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus</a><br>
<br></blockquote></div><br></div>