zoukankan      html  css  js  c++  java
  • 读取XML中数据库连接字符串配置 Helper

            /// <summary> 獲取連接字符串  DbConnection
            /// </summary>
            /// <param name="ls_DBSectionName"></param>
            /// <param name="ls_sXMLFile"></param>
            /// <returns></returns>
            private static OracleConnection DBOpen_Ora(string ls_DBSectionName, string ls_sXMLFile)
            {
                if (ls_sXMLFile == "")
                {
                    ls_sXMLFile = ls_XMLFile;
                }
                OracleConnection oracleConnection = null;
                string xMLNodeTxt = XMLHelper.GetXMLNodeTxt(ls_sXMLFile, ls_DBSectionName, "DBIP");
                string xMLNodeTxt2 = XMLHelper.GetXMLNodeTxt(ls_sXMLFile, ls_DBSectionName, "DBName");
                string xMLNodeTxt3 = XMLHelper.GetXMLNodeTxt(ls_sXMLFile, ls_DBSectionName, "UID");
                string xMLNodeTxt4 = XMLHelper.GetXMLNodeTxt(ls_sXMLFile, ls_DBSectionName, "PWD");
                string text = XMLHelper.GetXMLNodeTxt(ls_sXMLFile, ls_DBSectionName, "Port");
                if (text == "")
                {
                    text = "1521";
                }
                int li_Port = int.Parse(text);
                string oracleDBSource = getOracleDBSource(xMLNodeTxt, xMLNodeTxt2, li_Port);
                string connectionString = "Password=" + xMLNodeTxt4 + ";Persist Security Info=True;User ID=" + xMLNodeTxt3 + ";Data Source=" + oracleDBSource;
                oracleConnection = new OracleConnection(connectionString);
                //oracleConnection.Open();
                return oracleConnection;
            }
    
    
            private static string getOracleDBSource(string ls_DBIP, string ls_SvcName, int li_Port)
            {
                return "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = " + ls_DBIP + ")(PORT = " + li_Port.ToString() + ")) )(CONNECT_DATA =(SERVICE_NAME = " + ls_SvcName + ")))";
            }
    

      獲取XML中配置的數據庫連接字段,拼接數據庫連接字符串

  • 相关阅读:
    Hibernate入门
    安卓第四周作业
    第十三周作业
    第十三周上机作业
    第十二周作业
    第十二周上机作业
    第十一周作业
    第十一周上机作业
    第十周上机作业
    第九周上机作业
  • 原文地址:https://www.cnblogs.com/aDoc/p/12852392.html
Copyright © 2011-2022 走看看