zoukankan      html  css  js  c++  java
  • 操作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

  • 相关阅读:
    MockMvc control层单元测试 参数传递问题
    @GetMapping和@PostMapping接收参数的格式
    获取 request 中用POST方式"Content-type"是"application/x-www-form-urlencoded;charset=utf-8"发送的 json 数据
    测试驱动开发实践—从testList开始
    深度解读
    深度解读
    3年不辭職!記住,在石頭上也要坐3年!(但也要区分5种不值得留的公司,12种留不住人才的公司)
    Configuring Your EMS Server or EMS Console Server on Windows/Linux
    XML 标准诞生 20 周年:这个世界,它无处不在
    通富微电石明达:成熟接班人也是先进生产力(执行力+判断力=抄底)
  • 原文地址:https://www.cnblogs.com/songling/p/2121808.html
Copyright © 2011-2022 走看看