示例#1
0
 /// <summary>
 /// 获取单例的信息
 /// </summary>
 /// <param name="con">数据库连接字符串</param>
 /// <returns></returns>
 public static IDbHelper GetInstance(string con)
 {
     if (null == instance)
     {
         lock (lockHelper)
         {
             if (null == instance)
             {
                 instance = new MSSqlHelper(con);
             }
         }
     }
     return(instance);
 }
示例#2
0
        /// <summary>
        /// 获取数据库的操作对象,根据配置信息
        /// </summary>
        /// <param name="connKey"></param>
        /// <returns></returns>
        public static IDbHelper GetDbHelper(string connKey)
        {
            //先看连接的缓存,如果在缓存中存在,则直接返回缓存内容。
            if (dbHelperTemps.ContainsKey(connKey))
            {
                return(dbHelperTemps[connKey]);
            }

            IDbHelper dbHelper = null;
            ConnectionStringSettings connSetting = GetConnSetting(connKey);

            switch (connSetting.ProviderName)
            {
            case "System.Data.SqlClient":       //SqlServer数据库的处理
                dbHelper = MSSqlHelper.GetNewInstance(connSetting.ConnectionString);
                break;

            case "System.Data.SqlLite":
                dbHelper = SqliteHelper.GetNewInstance(connSetting.ConnectionString);
                break;

            case "System.Data.OracleClient":
                dbHelper = OracleHelper.GetNewInstance(connSetting.ConnectionString);
                break;

            case "MySql.Data.MySqlClient":
                dbHelper = MySqlHelper.GetNewInstance(connSetting.ConnectionString);
                break;

            default:
                break;
            }

            if (dbHelper != null)
            {
                dbHelperTemps.Add("dbconn", dbHelper);
            }
            return(dbHelper);
        }