*/
public static string[] GetOracleTnsNames()
{
try
{
// 查询注册表,获取oracle服务文件路径
RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("ORACLE");
string home = (string)key.GetValue("ORACLE_HOME");
string file = home + @"\network\ADMIN\tnsnames.ora";
// 解析文件
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();
// 返回字符串数组
return (string[])arr.ToArray(typeof(string));
}
catch (Exception ex)
{
return null;
}
} |