#region 获取tnsnames.ora路径
private string GetTNSNAMESORAFilePath()
{
RegistryKey rgkLm = Registry.LocalMachine;
RegistryKey rgkOracleHome = rgkLm.OpenSubKey("SOFTWARE").OpenSubKey("ORACLE");
string home = rgkOracleHome.GetValue("ORACLE_HOME").ToString();
string filePath = "";
if (!home.Equals(""))
{
filePath = home + @"\network\ADMIN\tnsnames.ora";
}
return filePath;
}
#endregion
#region 读取tnsnames.ora内容
private bool ReadData(string filePath)
{
bool flag = true;
try
{
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs,Encoding.Default);
string oraStr=sr.ReadToEnd();
sr.Close();
fs.Close();
}
catch
{
flag = false;
}
return flag;
}
#endregion
#region 追加tnsnames.ora文件内容
private bool WriteFile(string tnsnamesPath)
{
bool flag = true;
string carStr = txtServerName.Text.Trim().ToString()+" =" +
"(DESCRIPTION =" +
"(ADDRESS_LIST =" +
"(ADDRESS = (PROTOCOL = TCP)(HOST = "+txtHostName.Text.Trim().ToString()+")(PORT = "+txtPortNum.Text.Trim().ToString()+"))" +
")" +
"(CONNECT_DATA = (SID = "+txtSid.Text.Trim().ToString()+")(SERVER = DEDICATED))" +
")";
try
{
FileStream fs = new FileStream(tnsnamesPath, FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
sw.WriteLine(carStr);
sw.Close();
fs.Close();
}
catch
{
flag = false;
}
return flag;
}
#endregion