Ejemplo n.º 1
0
        public static void SaveConnection(ConnectionDetail connectionDetail)
        {
            var connectionElement = new ConnectionElement();
            connectionElement.FromConnectionDetail(connectionDetail);

            var configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var connectionsSection = (ConnectionSection) configuration.Sections["DBViewConnections"];
            if (connectionsSection != null)
                connectionsSection.Connections.Add(connectionElement);
            else
            {
                connectionsSection = new ConnectionSection();
                connectionsSection.Connections.Add(connectionElement);
                configuration.Sections.Add("DBViewConnections", connectionsSection);
            }
            connectionsSection.SectionInformation.ForceSave = true;
            configuration.Save(ConfigurationSaveMode.Full);
        }
Ejemplo n.º 2
0
        public static void DeleteConnection(ConnectionDetail connectionDetail)
        {
            var connectionElement = new ConnectionElement();
            connectionElement.FromConnectionDetail(connectionDetail);

            var configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var connectionsSection = (ConnectionSection) configuration.Sections["DBViewConnections"];
            if (connectionsSection == null) return;
            connectionsSection.Connections.Remove(connectionElement);
            connectionsSection.SectionInformation.ForceSave = true;
            configuration.Save(ConfigurationSaveMode.Full);
        }