Re: How to use tnsping programmatically

From: ddf <oratune_at_msn.com>
Date: Wed, 8 Apr 2009 11:27:10 -0700 (PDT)
Message-ID: <7bdefd10-41b4-4b33-be5e-078bc87bd591_at_z19g2000vbz.googlegroups.com>



Comments embedded.
On Apr 8, 8:43 am, "Strange Cat _at_ Work" <du..._at_dummy.com> wrote:
> > You can call tnsping from a shell script or a program, but how often
> > are you planning on running this check?
> > How often were you running your last check that managment or the
> > network team asked you not to run?
> > There is generally no real need to continuously check to see if the
> > database is there.  If the database is not there you will know in
> > fairly short order when the phone calls start coming in.  From within
> > an application you can just check the return code on the connect
> > call.  If the connect fails you will get an error code and you can
> > pass this on to an alert system (feature) to provide the database down/
> > unreachable error information.
>
> Thanx for answering Mark,
>
> the need is to avoid attempting the connection if the Oracle instance
> appears to be unreachable.

Simply because you can tnsping the listener doesn't mean the database is available.

> We're developing a panel pc app that has to
> connect to an Oracle server on demand (user touching screen and booking for
> canteen).
>

Again, just because you can tnsping the listener does not guarantee you can connect to the Oracle database, so your tnsping effort may succeed only to have the users receive the following error:

ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

Or this error, if the database is hard-coded into the listener.ora file:

ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist

> Problem is that the Oracle server happens to be on the other side of the
> mountains (and this is for real, no joke) and we've been warned about lack
> of connectivity/bandwidth on this connection.

Yes, the tnsping utility *can* prove you do have connectivity to the server if the listener is up. If the listener is down you'll receive an ORA-12541 error, which might indicate you can get to the server, and it might not.

>
> So, to make a long story short, what i'm trying to do is avoid connection
> (and users waiting for a timeout to occur in front of pc) if Oracle is not
> tnspingable...
>

Again I say that simply because tnsping returns error-free doesn't mean your database is running or that a connection attempt will be successful. Honestly I am not being negative, I am just trying to provide a realistic view of this situation.

> Other ideas are welcome, of course :)
>
> > HTH -- Mark D Powell --
>
> Thanx again
> Paolo

David Fitzjarrell Received on Wed Apr 08 2009 - 13:27:10 CDT

Original text of this message