Esempio n. 1
0
        /// <summary>
        /// 根据数据库类型,获取指定数据库连接
        /// </summary>
        /// <param name="dataBaseType"></param>
        /// <param name="optType">The optType<see cref="DBOptType"/></param>
        /// <returns></returns>
        private static IDbConnection GetDbConection(DBType dataBaseType, DBOptType optType = DBOptType.Read)
        {
            //根据数据库类型,获取指定数据库连接串
            var connectionString = GetDbConectionString(dataBaseType, optType);

            IDbConnection connection;

            switch (dataBaseType)
            {
            case DBType.MSSQL:
            default:
                connection = new SqlConnection(connectionString);
                //SimpleCRUD.SetDialect(SimpleCRUD.Dialect.SQLServer);
                break;

            case DBType.MYSQL:
                connection = new MySqlConnection(connectionString);
                //SimpleCRUD.SetDialect(SimpleCRUD.Dialect.MySQL);
                break;

            case DBType.SQLITE:
                connection = new SQLiteConnection(connectionString);
                //SimpleCRUD.SetDialect(SimpleCRUD.Dialect.SQLite);
                break;
            }
            //connection.Open();

            return(connection);
        }
Esempio n. 2
0
        /// <summary>
        /// 根据数据库类型,获取指定数据库连接串
        /// </summary>
        /// <param name="dataBaseType"></param>
        /// <param name="optType">The optType<see cref="DBOptType"/></param>
        /// <returns></returns>
        private static string GetDbConectionString(DBType dataBaseType, DBOptType optType = DBOptType.Read)
        {
            var connString = string.Empty;

            var configKey = string.Format("Gseey:Connections:{0}Db{1}ConnectionString",
                                          dataBaseType.ToString().ToUpper(),
                                          optType.ToString().ToUpper());

            connString = ConfigHelper.Get(configKey);

            return(connString);
        }