public static DbConnection GetDBConnecton(string connectionString, Enums.DatabaseAdapter adapter) { DbConnection connection = new MySqlConnection(connectionString); if (string.IsNullOrEmpty(connectionString)) { throw new Exception("Invalid connection string"); } switch (adapter) { case Enums.DatabaseAdapter.sqlconnection: connection = new SqlConnection(connectionString); break; case Enums.DatabaseAdapter.npgsqlconnection: connection = new OracleConnection(connectionString); break; default: connection = new MySqlConnection(connectionString); break; } try { connection.Open(); } catch (Exception ex) { throw new Exception("An error occured while connecting to the database. See innerException for details.", ex); } return(connection); }
public UserData(IOptions <DatabaseSettings> dbOptions, IUserRoleData userRoleData) : base(dbOptions) { this._settings = dbOptions.Value; this._connectionString = this._settings.Main.ConnectionString; this._dbAdapter = this._settings.Main.Adapter; this._userRoleData = userRoleData; }
public Repository(IOptions <DatabaseSettings> dbOptions) { this._settings = dbOptions.Value; this._connectionString = this._settings.Main.ConnectionString; this._dbAdapter = this._settings.Main.Adapter; SqlMapperExtensions.GetDatabaseType = conn => this._settings.Main.Adapter.ToString(); }
public RoleData(IOptions <DatabaseSettings> dbOptions) : base(dbOptions) { this._settings = dbOptions.Value; this._connectionString = this._settings.Main.ConnectionString; this._dbAdapter = this._settings.Main.Adapter; }