Forum > Databases

ODBC Time connection

(1/1)

lcapitanache:
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:

--- Quote from: lcapitanache 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?

--- End quote ---
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

lcapitanache:

--- Quote from: Zvoni on May 28, 2024, 07:38:00 am ---
--- Quote from: lcapitanache 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?

--- End quote ---
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

--- End quote ---

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.

Navigation

[0] Message Index

Go to full version