Solved

Parsing tnsnames.ora for SID names in VB.net

Posted on 2007-03-27
4
1,722 Views
Last Modified: 2013-12-19
I have been searching around and did not find an exact match to this question.

Using VB.NET 2005, what would be the best way to parce the SID names from the TNSNAMES.ORA file.
I am looking to enumerate this list into a ComboBox for Oracle Authenication.

I was looking at regex but am not sure.

Also, can I get an example?

Here is what I have: Visual Studio .NET 2005, Oracle 9I, Oracle Data Adaptor.
0
Comment
Question by:tnowacoski
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
ID: 18803176
Off the top of my head and w/o trying it, I'm thinking a regular expression matcher.  Something like:  "^[A-Za-z0-9] =$"

Again, I doubt that regex will plug right in but you get the idea.  Oracle is funny about the layout of its config files so any line starting with an alpha and ending with "<space>=" should be an alias.  Then all you need to do is rtrim the "<space>=" and you have the name.
0
 

Author Comment

by:tnowacoski
ID: 18803248
I must confess, I am new to regex, not really sure how to do this
0
 
LVL 17

Assisted Solution

by:NicksonKoh
NicksonKoh earned 250 total points
ID: 18806297
Hi tnowacoski,

My VB.NET is very rusty. Haven't touch it for a long time :p. Below is a VBScript sample I wrote which you should be able to convert easily to .NET.

Dim re as RegExp
Dim m as Match
Dim matches as Matches

Set re = New RegExp
re.IgnoreCase = true
re.Global = true
re.Pattern = "([^\s]+)\s*=\s*\s\(DESCRIPTION\s*="
Set matches = re.Execute (strText)    'strText is the text stream output from tnsnames.ora
For each m in matches
   strSID = m.submatch(0)
   MsgBox(strSID)
Next


Cheers,
NicksonKoh
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 18808050
Here's my attempt.

I'm not sure what permissions you would need to grant to read the tnsnames file from ORACLE_HOME so this example expects it to be in the current directory.
--------------------------

<%@ import namespace = "System" %>
<%@ import namespace = "System.IO" %>

<html>
<title>Regex Sample</title>

<body>

<script language="vb" runat="server">

      sub page_load(sender as object, e as eventargs)


            Dim FILENAME as String = Server.MapPath("tnsnames.ora")
            Dim objStreamReader as StreamReader
            objStreamReader = File.OpenText(FILENAME)

            Dim contents as String = objStreamReader.ReadToEnd()


            objStreamReader.Close()

            Dim pat As String = "^\w*\s="

            Dim r As New Regex(pat, RegexOptions.MultiLine)
            Dim m As Match = r.Match(contents)

            While m.Success
                  response.write("<BR>Match=" + replace(m.ToString()," =",""))
                  m = m.NextMatch()
            End While

      end sub

</script>

</form>
</body>
</html>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question