/// <summary> /// Initializes a new instance of the <see cref="DBHelper" /> class. /// </summary> /// <param name="ReadOnly">if set to <c>true</c> [read only].</param> public DBHelper(bool ReadOnly) { var configDbType = ConfigHelper.GetConfigToString(ConfigKeyForDataBaseType); if (string.IsNullOrWhiteSpace(configDbType)) { configDbType = "MySql"; } _dbType = configDbType; if (ReadOnly) { _connStr = ConfigHelper.GetConfigToString(ReadConn); } if (string.IsNullOrWhiteSpace(_connStr)) { _connStr = ConfigHelper.GetConfigToString(WriteConn); } if (string.IsNullOrWhiteSpace(_connStr)) { throw new Exception("数据库连接未配置,无法正常连接数据库,请在配置文件appSettings节点下配置ConnString,可扩展配置ConnStringRead(只读实例)"); } _db = GetDBOperator(_dbType, _connStr); _db.Open(); }
/// <summary> /// 构造函数 /// </summary> /// <param name="dbType">数据库类型(MYSQL/ORACLE/SQLSERVER/POSTGRESQL)</param> /// <param name="connStr">连接字符串</param> public DBHelper(string dbType, string connStr) { _dbType = dbType; _connStr = connStr; if (string.IsNullOrWhiteSpace(_connStr)) { throw new Exception("数据库连接未配置,无法正常连接数据库,请在配置文件appSettings节点下配置ConnString,可扩展配置ConnStringRead(只读实例)"); } _db = GetDBOperator(dbType, connStr); _db.Open(); }
/// <summary> /// 构造函数 /// </summary> /// <param name="connStr">连接字符串</param> public DBHelper(string connStr) { var configDbType = ConfigHelper.GetConfigToString(ConfigKeyForDataBaseType); if (string.IsNullOrWhiteSpace(configDbType)) { configDbType = "MySql"; } _dbType = configDbType; _connStr = connStr; _db = GetDBOperator(_dbType, connStr); _db.Open(); }
/// <summary> /// Initializes a new instance of the <see cref="DBHelper" /> class. /// </summary> /// <param name="ReadOnly">if set to <c>true</c> [read only].</param> /// <param name="dbType">Type of the database.</param> /// <param name="connStr">The connection string.</param> /// <exception cref="System.Exception">数据库连接未配置,无法正常连接数据库,请在配置文件appSettings节点下配置ConnString,可扩展配置ConnStringRead(只读实例)</exception> public DBHelper(bool ReadOnly, string dbType, string connStr) { _dbType = dbType; _connStr = connStr; if (ReadOnly) { _connStr = ConfigHelper.GetConfigToString(ReadConn); } if (string.IsNullOrWhiteSpace(_connStr)) { _connStr = ConfigHelper.GetConfigToString(WriteConn); } if (string.IsNullOrWhiteSpace(_connStr)) { throw new Exception("数据库连接未配置,无法正常连接数据库,请在配置文件appSettings节点下配置ConnString,可扩展配置ConnStringRead(只读实例)"); } _db = GetDBOperator(_dbType, _connStr); _db.Open(); }