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

  • 相关阅读:
    阶梯式测试
    websocket协议
    性能指标
    环境变量
    解密断言+参数写入文本
    将参数进行URL编码
    日志级别
    对返回结果进行断言
    python小题目:循环/函数
    如果使用JSON提取器 和正则提取器
  • 原文地址:https://www.cnblogs.com/songling/p/2121808.html
Copyright © 2011-2022 走看看