/// <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中配置的數據庫連接字段,拼接數據庫連接字符串