/*
获取Oracle服务名
1。查询注册表,获取Oracle, dan Oracle
alamat:HKEY_LOCAL_MACHINESOFTWAREORACLEORACLE_HOME REG_SZ E:ORACLEORA92
得知oracle服务名文件所在地:根目录networkADMINtnsnames.ora
2。解析该文件,该文件结构如
# ------------------------------------------------
PORTAL =
(DESKRIPSI =
(ADDRESS_LIST =
(ALAMAT = (PROTOKOL = TCP)(HOST = 134.104.52.6)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = portal)
)
)
3。解析要点:
layanan asuransi kesehatan
跳过以#打头的注释行
Panduan Pengguna OracleA~z之间的行就包含了Oracle服务名
截取该行第一个“=”号左边的字符串,trim处理后就是Oracle服务名了
*/
string statis publik[] GetOracleTnsNames()
{
mencoba
{
// 查询注册表,获取Oracle服务文件路径
Kunci RegistryKey = Registry.LocalMachine.OpenSubKey("PERANGKAT LUNAK").OpenSubKey("ORACLE");
string home = (string)kunci.GetValue("ORACLE_HOME");
string file = home + @"networkADMINtnsnames.ora";
// 解析文件
garis senar;
ArrayList arr = Daftar Array baru();
StreamReader sr = StreamReader baru(file);
while ((baris = sr.ReadLine()) != null)
{
baris = baris.Trim();
jika (baris != "")
{
karakter c = baris[0];
jika ( c>= 'A' && c<='z')
arr.Tambahkan(baris.Substring(0, baris.IndexOf(' ')));
}
}
sr.Tutup();
// 返回字符串数组
kembali (string[])arr.ToArray(typeof(string));
}
menangkap (Pengecualian ex)
{
kembalikan nol;
}
}
http://www.cnblogs.com/surfsky/archive/2006/08/29/489682.html