?
Solved

Parsing tnsnames.ora for SID names in VB.net

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Suggested Courses

770 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