?
Solved

Parsing tnsnames.ora for SID names in VB.net

Posted on 2007-03-27
4
Medium Priority
?
1,754 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 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1000 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 1000 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 78

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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

830 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