private static void createDataBaseSetingsGroup() { DataBaseSettingsGroup = new ConfigurationSectionGroup(); config.SectionGroups.Add("DataBaseSetings", DataBaseSettingsGroup); if (ConnectionStrings.Count > 0) { bool first = true; foreach (ConnectionStringSettings conn in ConnectionStrings) { if (conn.ProviderName == "System.Data.EntityClient") { DataBaseSection secion = new DataBaseSection(); secion.Settings = new DataBaseSetttingsElement(first); if (first) { first = false; } DataBaseSettingsGroup.Sections.Add(conn.Name, secion); } } } config.Save(ConfigurationSaveMode.Modified); }
public static List <DataBaseSettings> GetDataBaseSettings() { List <DataBaseSettings> dataBases = new List <DataBaseSettings>(); if (ConnectionStrings.Count > 0) { foreach (ConnectionStringSettings conn in ConnectionStrings) { if (conn.ProviderName == "System.Data.EntityClient") { EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(conn.ConnectionString); SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(entityBuilder.ProviderConnectionString); DataBaseSection databaseSection = (DataBaseSection)DataBaseSettingsGroup.Sections[conn.Name]; dataBases.Add(new DataBaseSettings() { Name = conn.Name, OrginalName = conn.Name, Server = sqlBuilder.DataSource, Catalog = sqlBuilder.InitialCatalog, IntegratedSecurity = sqlBuilder.IntegratedSecurity, UserId = sqlBuilder.UserID, Password = sqlBuilder.Password, ConnectionString = conn.ConnectionString, ProviderConnectionString = entityBuilder.ProviderConnectionString, Default = databaseSection == null ? false : databaseSection.Settings.Default, IsNew = false }); } } } return(dataBases); }