Recent

Author Topic: ODBC Time connection  (Read 1766 times)

lcapitanache

  • Newbie
  • Posts: 5
ODBC Time connection
« on: May 27, 2024, 09:23:03 pm »
Hello,

I have an application in Lazarus that connects to a MS Access 2007 database that is on a shared resource on a local network through an ODBCConnection control. The program works correctly and I can perform SQL queries without any problem.

However, I have noticed that when the computer hosting the database is not available, my Lazarus application hangs waiting for the connection. I have searched, but I see that the ODBCConnection control does not have a Timeout property to set. In this scenario, how could I set a connection timeout of, say, two seconds, so that I can display a database unavailable error message?

Zvoni

  • Hero Member
  • *****
  • Posts: 2741
Re: ODBC Time connection
« Reply #1 on: May 28, 2024, 07:38:00 am »
Hello,

I have an application in Lazarus that connects to a MS Access 2007 database that is on a shared resource on a local network through an ODBCConnection control. The program works correctly and I can perform SQL queries without any problem.

However, I have noticed that when the computer hosting the database is not available, my Lazarus application hangs waiting for the connection. I have searched, but I see that the ODBCConnection control does not have a Timeout property to set. In this scenario, how could I set a connection timeout of, say, two seconds, so that I can display a database unavailable error message?
Since Access is a filebased database, why don't you just check if the FileExists (hint!)?

EDIT: Found this: https://forum.lazarus.freepascal.org/index.php?topic=57218.0
Funny enough: Didn't remember anymore...
No idea if it works for Access
« Last Edit: May 28, 2024, 07:42:52 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

lcapitanache

  • Newbie
  • Posts: 5
Re: ODBC Time connection
« Reply #2 on: May 29, 2024, 09:29:26 pm »
Hello,

I have an application in Lazarus that connects to a MS Access 2007 database that is on a shared resource on a local network through an ODBCConnection control. The program works correctly and I can perform SQL queries without any problem.

However, I have noticed that when the computer hosting the database is not available, my Lazarus application hangs waiting for the connection. I have searched, but I see that the ODBCConnection control does not have a Timeout property to set. In this scenario, how could I set a connection timeout of, say, two seconds, so that I can display a database unavailable error message?
Since Access is a filebased database, why don't you just check if the FileExists (hint!)?

EDIT: Found this: https://forum.lazarus.freepascal.org/index.php?topic=57218.0
Funny enough: Didn't remember anymore...
No idea if it works for Access

Hi, thank you very much for your time.

I tried your idea of verifying the existence of the database file first, but I had exactly the same problem. The application hangs looking for the existence of the file on the host.

I solved the problem by changing the approach a bit. What I did was to elaborate a function that sends a ping to the computer host, and based on its response I either open the database or display an unavailability error message.

 

TinyPortal © 2005-2018