Sathya Sathya - 26 days ago 7
C# Question

Parsing tnsnames.ora in Visual C# 2008

How I parse tnsnames.ora file using Visual C# (Visual Studio 2008 Express edition) to get the tnsnames ?
For instance, my tnsnames.ora file contains

ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = shaman)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
BILL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.58)(PORT = 1522))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)


How can I parse this file to get the TNSNAMES (ie, ORCL, BILL etc). Forgive me if this question sounds too obvious, I'm learning & trying my hand in C#

Mac Mac
Answer

First of all, you will need the syntax rules for this file.

There is probably a hack for this, but I would personally go with a full parser, like ANTLR combined with the proper grammar (a complete list of ANTLR grammars can be found here).