• 操作oracle的tnsnames.ora文件


     #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

  • 相关阅读:
    ArrayList源码 (基于1.7)
    java.lang.Class类中的某些方法
    jdk1.8新特性 : 接口中可以有普通方法(非静态方法)和静态方法 , 颠覆了之前我的理解 : 接口中只能有共有常量和抽象方法的概念,后面必须要加一句jdk1.7和1..7之前
    Cesium中级教程10
    Cesium中级教程9
    Cesium中级教程8
    Cesium中级教程7
    Cesium中级教程6
    Cesium中级教程5
    Cesium中级教程4
  • 原文地址:https://www.cnblogs.com/songling/p/2121808.html
Copyright © 2020-2023  润新知