Firebird connection timeout

Posted on 2013-12-14
Last Modified: 2013-12-24
I have an application that accesses a Firebird database managed by a remote Firebird server.
If there is not activity between the application and the database for a given time (I didn't test for how long it is), then if the application starts some work with the connected firebird server, it gets : "Unable to complete network request to host "....". Error reading data from the connection. An existing connection has been closed by the host" (last phrase I translated from french)
I understand that very well but I want to fix it.
In my code, each time I start some SQL activity, I check if the Connected property of the TIBDatabase is true and if not, I set it to true.
The problem here is that the application see it as true but it is practically not as the host has stopped it !
So my question, what is the best code I can write to "reopen" the connection IF AND ONLY IF IT has been close by the host
Question by:LeTay
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
  • 5
  • 4
  • 2
LVL 19

Expert Comment

ID: 39719679
your problem is that the application doesn't know the connection has gone down until it tries to use it

you need to do a query to test it

Author Comment

ID: 39719680
I understand that but once issuing the query, it will fail so what will I have to code in the exception block to reconnect to it ?
LVL 19

Expert Comment

ID: 39719691
yes, catch the exception and reconnect

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


Author Comment

ID: 39719695
You mean, "simply" IBDB.Connected := True ?
Will it "understand" that correctly as the property is already (incorrectly) True ?
LVL 19

Expert Comment

ID: 39719715
no, just setting the flag to true will not do it

I don't know which library you are using but somewhere you must have a call that actually connects to the database, you will need to run that again

Author Comment

ID: 39719807
Well using interbase of Delphi
In my code, I connect to the database by setting its connected property to True, nothing else
LVL 38

Accepted Solution

Geert Gruwez earned 500 total points
ID: 39721113
this is a firewall problem
> when no activity occurs on a connection, it gets severed by the firewall

they will deny it at first due to ignorance
> it usually takes a lot of negotation to solve this problem as the people taking care of the firewall are unaware of this problem
the firewall software should have a log of this

there will be a parameter for this set to 30 minutes on the firewall

a workaround is to have a timer execute a trivial meaningless query every 20 minutes
this sometimes referred to as a heartbeat

if they are unwilling to cooperate (which does happen)
explain them they have following choice:
> you implement the heartbeat query and cause unnecessary excess network traffic
  >> you could setup a test query, which loads massive amounts of data from the database every time
> find the firewall parameter and add an exclusion (or switch the feature off)

they will ask you what port you are connecting to
> this depends on the setup of the firebird database and client

but it's always best to try and work together first ... :)
you could setup 2 programs ... 1 with heartbeat and 1 without
> and then you'll see the one without heartbeat having the problem and the other one won't have the problem
LVL 19

Expert Comment

ID: 39721202
the default port is 3050

Author Comment

ID: 39722692
Do you mean a firewall at client side ?

Author Comment

ID: 39722715
Hello, I come back on that firewall stuff
When I run the application on my own PC, where indeed the Firebird server is located, the timeout also happens (no firewall is running on my PC, I have an ADSL router)
LVL 38

Expert Comment

by:Geert Gruwez
ID: 39723339
why do you indicate you have an ADSL router ?
if you are doing this over internet through your ADSL router then the path you use passes by a provider ...
are you sure this provider doesn't have a firewall ?

you need a map of your IT landscape and all the components in it.
anything on the network path can sever (or interrupt) a connection

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

628 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