static List <EVConfigurationItem> LoadConfigurationFromDatabase() { var configItems = new List <EVConfigurationItem>(); var connectionString = ConfigurationManager.ConnectionStrings["EV"].ConnectionString; // @"Data Source=EVDBALIAS;Initial Catalog=ConfigPoC;User Id=sa;Password=Admin@2010;"; const string query = "SELECT * FROM dbo.EVConfiguration"; var sqlConnection = new SqlConnection(connectionString); var sqlCommand = new SqlCommand(query, sqlConnection); sqlConnection.Open(); using (var dr = sqlCommand.ExecuteReader()) { while (dr.Read()) { var configItem = new EVConfigurationItem { Section = (dr["Section"] != DBNull.Value) ? dr["Section"].ToString().ToLower() : string.Empty, Application = (dr["Application"] != DBNull.Value) ? dr["Application"].ToString().ToLower() : string.Empty, SubApplication = (dr["SubApplication"] != DBNull.Value) ? dr["SubApplication"].ToString().ToLower() : string.Empty, ConfigKey = (dr["ConfigKey"] != DBNull.Value) ? dr["ConfigKey"].ToString().ToLower() : string.Empty, ConfigValue = (dr["ConfigValue"] != DBNull.Value) ? dr["ConfigValue"].ToString() : string.Empty }; configItems.Add(configItem); } } sqlConnection.Close(); return(configItems); }
static List<EVConfigurationItem> LoadConfigurationFromDatabase() { var configItems = new List<EVConfigurationItem>(); var connectionString = ConfigurationManager.ConnectionStrings["EV"].ConnectionString; // @"Data Source=EVDBALIAS;Initial Catalog=ConfigPoC;User Id=sa;Password=Admin@2010;"; const string query = "SELECT * FROM dbo.EVConfiguration"; var sqlConnection = new SqlConnection(connectionString); var sqlCommand = new SqlCommand(query, sqlConnection); sqlConnection.Open(); using (var dr = sqlCommand.ExecuteReader()) { while (dr.Read()) { var configItem = new EVConfigurationItem { Section = (dr["Section"] != DBNull.Value) ? dr["Section"].ToString().ToLower() : string.Empty, Application = (dr["Application"] != DBNull.Value) ? dr["Application"].ToString().ToLower() : string.Empty, SubApplication = (dr["SubApplication"] != DBNull.Value) ? dr["SubApplication"].ToString().ToLower() : string.Empty, ConfigKey = (dr["ConfigKey"] != DBNull.Value) ? dr["ConfigKey"].ToString().ToLower() : string.Empty, ConfigValue = (dr["ConfigValue"] != DBNull.Value) ? dr["ConfigValue"].ToString() : string.Empty }; configItems.Add(configItem); } } sqlConnection.Close(); return configItems; }