Solved

Parsing tnsnames.ora for SID names in VB.net

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

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now