Asp. NET tip: Get a configured Oracle service name on this machine

Source: Internet
Author: User
Tags net return trim root directory
asp.net|oracle| Tips

/*
Get Oracle Service Name
1. Querying the registry for Oracle installation root directory
such as: Hkey_local_machine\software\oracle\oracle_home REG_SZ E:\ORACLE\ORA92
Learned Oracle Service name file location: root directory \network\admin\tnsnames.ora

2. Resolves the file, which is structured like
# ------------------------------------------------
PORTAL =
(DESCRIPTION =
(Address_list =
(address = (PROTOCOL = TCP) (HOST = 134.104.52.6) (PORT = 1521))
)
(Connect_data =
(service_name = portal)
)
)

3. Analytical Essentials:
Row by row get again parse
Skip the comment line with #
After filtering out the spaces, the line between the first character and the a~z contains the Oracle service name
Intercepts the string to the left of the first "=" number on the line, which is the Oracle service name after the trim process
*/
public static string[] Getoracletnsnames ()
{
Try
{
Querying the registry for Oracle service file paths
RegistryKey key = Registry.LocalMachine.OpenSubKey ("SOFTWARE"). OpenSubKey ("ORACLE");
String home = (string) key. GetValue ("Oracle_home");
string file = home + @ "\network\admin\tnsnames.ora";

Parsing files
String line;
ArrayList arr = new ArrayList ();
StreamReader sr = new StreamReader (file);
while (line = Sr. ReadLine ())!= null)
{
line = line. Trim ();
if (line!= "")
{
char C = line[0];
if (c>= ' A ' && c<= ' z ')
Arr. ADD (line. Substring (0, line. IndexOf (")");
}
}
Sr. Close ();

Returns an array of strings
Return (string[]) arr. ToArray (typeof (String));
}
catch (Exception ex)
{
return null;
}
}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.