Search code examples
c#oracleoledb

C# & .NET Checking Database Connection


I want to check availability of database connection so that I could put my application in specific modes; online mode and offline mode.

In order to do so, I try to open an OleDB connection (the database is Oracle) and if it is successful, the application shall run in online mode. However, if the database is down, opening the connection shall only be closed after specific period of time due to timeout.

Is there specific way of doing this without having to wait for the timeout? Or maybe, specify the timeout interval?


Solution

  • There is no other way then connecting to the database service.

    However you could Mmdify the ConnectionTimeout property of your Connection instance before opening it to tweak the amount of time you want to wait.

    On the other hand you could always start with the offline mode, do the connection check async and change the application behavior when the check was succeeded.