Example #1
0
        /// <summary>
        /// 连接测试库
        /// </summary>
        /// <param name="dataBaseEnum"></param>
        /// <param name="dBEnum"></param>
        /// <param name="dBNetEnumType"></param>
        /// <returns></returns>
        public MySqlConnection DataBaseConnTest(DBNameEnumType dataBaseEnum, DBEnumType?dBEnum = null, DBNetEnumType?dBNetEnumType = null)
        {
            var key      = string.Empty;
            var extranet = isExtranet ? 1 : 0;

            if (dBNetEnumType.HasValue)  //内外网,优先使用程序中的
            {
                extranet = (int)dBNetEnumType.Value;
            }
            key = dataBaseEnum.ToString() + "_" + (int)DBEnumType.测试库 + "_" + extranet;
            var DBConnString = dicDataBase[key];

            if (string.IsNullOrWhiteSpace(DBConnString))
            {
                throw new Exception("数据库连接错误");
            }
            var connection = new MySqlConnection(DBConnString);

            SimpleCRUD.SetDialect(SimpleCRUD.Dialect.MySQL);
            connection.Open();
            return(connection);
        }
Example #2
0
        /// <summary>
        /// 数据库连接
        /// </summary>
        /// <param name="dataBaseEnum"></param>
        /// <param name="dBEnum"></param>
        /// <param name="dBNetEnumType"></param>
        /// <returns></returns>
        public MySqlConnection DataBaseConn(DBNameEnumType dataBaseEnum, DBEnumType?dBEnum = null, DBNetEnumType?dBNetEnumType = null)
        {
            var key      = string.Empty;
            var database = 0;
            var extranet = isExtranet ? 1 : 0;

            if (dBEnum.HasValue)
            {
                database = (int)dBEnum.Value;
            }
            else
            {
                database = (int)DBEnumType.主库;
            }
            if (dataBase == "AliYunTest")  //数据库类型,优先使用配置文件的
            {
                database = (int)DBEnumType.测试库;
            }
            else if (dataBase == "LocalHost")
            {
                database = (int)DBEnumType.本地测试库;
            }
            if (dBNetEnumType.HasValue)  //内外网,优先使用程序中的
            {
                extranet = (int)dBNetEnumType.Value;
            }
            key = dataBaseEnum.ToString() + "_" + database + "_" + extranet;
            var DBConnString = dicDataBase[key];

            if (string.IsNullOrWhiteSpace(DBConnString))
            {
                throw new Exception("数据库连接错误");
            }
            var connection = new MySqlConnection(DBConnString);

            SimpleCRUD.SetDialect(SimpleCRUD.Dialect.MySQL);
            connection.Open();
            return(connection);
        }