Solved

Parsing tnsnames.ora for SID names in VB.net

Posted on 2007-03-27
4
1,714 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
  • 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

Technology Partners: 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

Suggested Solutions

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

733 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