How to know the database is online or not @_@

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
tangaslie
Posts: 8
Joined: Mon 11 Aug 2008 08:47

How to know the database is online or not @_@

Post by tangaslie » Thu 15 Jan 2009 08:57

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

Shalex
Site Admin
Posts: 8248
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Thu 15 Jan 2009 13:24

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:

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.

tangaslie
Posts: 8
Joined: Mon 11 Aug 2008 08:47

Post by tangaslie » Fri 16 Jan 2009 02:42

I found that the performance is very fast at the Connection.Open even it is not connecting to the database. However, when the program run this statement:

Dim myReader As OracleDataReader = myCommand.ExecuteReader()

it takes about 15-20 seconds before go to CATCH statement.

Thanks

Shalex
Site Admin
Posts: 8248
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Fri 16 Jan 2009 13:28

We don't know the faster way. This delay is caused by OCI.

tangaslie
Posts: 8
Joined: Mon 11 Aug 2008 08:47

Post by tangaslie » Mon 19 Jan 2009 09:15

May I know is there are any solution to change the OCI timeout property?

Thanks

Shalex
Site Admin
Posts: 8248
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Mon 19 Jan 2009 13:42

The OCI timeout property can not be changed.

tangaslie
Posts: 8
Joined: Mon 11 Aug 2008 08:47

Post by tangaslie » Tue 20 Jan 2009 01:33

Actually, we tried to use the Direct mode to connect the database. The system got an error:

"Unknown connection string parameter Direct."

My Corelab.Oracle version is 4.75.42.1 and runtime version is v2.0.50727. If the version 5.x can solve this problem, is there are any free upgrade?

Thanks

Shalex
Site Admin
Posts: 8248
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Tue 20 Jan 2009 08:50

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.

Post Reply