1
yangle
2023-09-20 67aad437a7ed836a1d6e865d8529d52e08585ddd
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
35
36
37
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
 
namespace WebAPI.Dapper
{
    public class SqlPools
    {
        public SqlPools()
        {
            SecConnStr();
        }
        static Dictionary<string, string> sqlDic = new Dictionary<string, string>();
        /// <summary>
        /// 将配置文件夹中的数据库链接全部遍历至字典
        /// </summary>
        private void SecConnStr()
        {
            ConnectionStringSettingsCollection seetings = ConfigurationManager.ConnectionStrings;//获取配置文件connectionstring所有节点
            for (int i = 0; i < seetings.Count; i++)
            {
                sqlDic.Add(seetings[i].Name, seetings[i].ConnectionString);//存入字典
            }
        }
        /// <summary>
        /// sqlhelper实例化
        /// </summary>
        /// <param name="dbName"></param>
        /// <returns></returns>
        public static SqlHelper GetInstance(string dbName)
        {
            return new SqlHelper(sqlDic[dbName]);//从字典取出数据库链接字符串
        }
    }
}