How to know the database is online or not @_@
How to know the database is online or not @_@
Dear all,
I am using the handheld to insert the data to the Oracle database frequently. We cannot afford any data losing. Therefore, we have an Online Mode and Offline Mode in programming. If the database is online we will insert the data immediately. Otherwise, we will write it on a text file. Recently, we do not know the database is online or not so that we don’t know how to do it. What can I do beside the TRY CATCH statement?
Thanks,
Aslie
I am using the handheld to insert the data to the Oracle database frequently. We cannot afford any data losing. Therefore, we have an Online Mode and Offline Mode in programming. If the database is online we will insert the data immediately. Otherwise, we will write it on a text file. Recently, we do not know the database is online or not so that we don’t know how to do it. What can I do beside the TRY CATCH statement?
Thanks,
Aslie
The state of the OracleConnection object can be checked by the help of its State property. But the database can be unavailable even if the OracleConnection.State property is ConnectionState.Open. Therefore execute some query to ensure the connection is valid before using the OracleConnection object.
We recommend to use the try...catch statement:
We recommend to use the try...catch statement:
Code: Select all
try {
if (connection.State != ConnectionState.Open)
connection.Open();
OracleCommand command = new OracleCommand("begin null; end;", connection);
command.ExecuteNonQuery();
// code that works with database
}
catch {
//code that works with file
}
Last edited by Shalex on Fri 16 Jan 2009 13:09, edited 1 time in total.
Probably you are using Mobile Edition of dotConnect for Oracle. Mobile Edition doesn't use Oracle client software, it can work only in Direct mode (the Direct property is always set to true). That's why it is not allowed to set/change this property. The Timeout property is not available in Mobile Edition.
Please refer to http://www.devart.com/forums/viewtopic.php?p=42076 , where this issue is discussed.
Please refer to http://www.devart.com/forums/viewtopic.php?p=42076 , where this issue is discussed.