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

posted @   Yookee  阅读(175)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示