读取XML中数据库连接字符串配置 Helper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | /// <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中配置的數據庫連接字段,拼接數據庫連接字符串
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步