Question

Is there an API that will read a TNS file and present it in some easy-to-use data structure?

I would like to get a list of all my TNS entries. This works but is not particularly elegant!

grep '^[a-zA-Z].*=' /etc/tnsnames.ora | sed 's/[ =].*//'
Was it helpful?

Solution

Another, not very simple, solution is ANTLR. You can use ANTLR to parse tnsnames.ora. On ANTLR Grammar List page you will find grammar which can parse tnsnames.ora, sqlnet.ora and listener.ora

OTHER TIPS

I'm not sure if TNSPing would be more useful to you. It will output like:

TNS Ping Utility for Linux: Version 10.2.0.1.0 - Production
on 01-MAR-2009 02:02:33

Copyright (c) 1997, 2005, Oracle.  All rights reserved.

Used parameter files:

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)
(HOST = myhostname)(PORT = 1521)) (CONNECT_DATA = (SID = mydb)))
OK (80 msec)

The problem is you must pass it the TNS name to ping, which may or may not be possible in your scenario.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top