/// <summary>
 /// 
 /// </summary>
 /// <param name="connectionString"></param>
 /// <param name="setStoredProcedure"></param>
 /// <param name="section"></param>
 /// <param name="configurationSection"></param>
 public void Save(string connectionString, string setStoredProcedure, string section, SerializableConfigurationSection configurationSection)
 {
     ValidateArgumentsAndConnectionInfo(connectionString, setStoredProcedure, section, configurationSection);
     
     //TODO:  need to modify this to use arguments passed in -- can I make modifications to just call SqlConfigurationManager.SaveSection(connectionString, setStoredProcedure, section, configurationSection);
     
     implementationByConnectionString[connectionString].SaveSection(section, configurationSection);
 }
        /// <summary>
        /// 
        /// </summary>
        public void SaveSection(string sectionName, SerializableConfigurationSection configurationSection)
        {
            //TODO: if encryption enabled, encrypt it here

            // Create Instance of Connection and Command Object
            using (SqlConnection myConnection = new SqlConnection(data.ConnectionString))
            {
                try
                {
                    SqlCommand myCommand = new SqlCommand(data.SetStoredProcedure, myConnection);
                    myCommand.CommandType = CommandType.StoredProcedure;

                    SqlParameter sectionNameParameter = new SqlParameter(@"@section_name", SqlDbType.NVarChar);
                    sectionNameParameter.Value = sectionName;
                    myCommand.Parameters.Add(sectionNameParameter);

                    SqlParameter sectionTypeParameter = new SqlParameter(@"@section_type", SqlDbType.NVarChar);
                    sectionTypeParameter.Value = configurationSection.GetType().AssemblyQualifiedName;
                    myCommand.Parameters.Add(sectionTypeParameter);

                    SqlParameter sectionValueParameter = new SqlParameter(@"@section_value", SqlDbType.NText);

                    StringBuilder output = new StringBuilder();
                    XmlWriterSettings settings = new XmlWriterSettings();
                    using (XmlWriter writer = XmlWriter.Create(output, settings))
                    {
                        configurationSection.WriteXml(writer);
                        writer.Close();
                        writer.Flush();
                    }

                    sectionValueParameter.Value = output.ToString();
                    myCommand.Parameters.Add(sectionValueParameter);

                    // Execute the command
                    myConnection.Open();
                    myCommand.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    throw new ConfigurationErrorsException(Resources.ExceptionConfigurationCannotSet, e);
                }
            }
        }
        /// <summary>
        /// Saves a section from SqlConfiguration, and starts watching for 
        /// its changes if not watching already.
        /// </summary>
        /// <param name="sectionName">The section name.</param>
        /// <param name="section">The section.</param>
        /// <returns></returns>
        public void SaveSection(string sectionName, SerializableConfigurationSection section)
        {
            if (section == null) throw new ArgumentNullException("section");
            if ((sectionName == null) || (sectionName.Trim().Equals(String.Empty)))
                throw new ArgumentNullException(sectionName);

            SqlConfigurationManager.SaveSection(sectionName,section,data);

            lock (lockMe)
            {
                if (!IsWatchingSection(sectionName))
                {
                    SetWatcherForSection(sectionName, section.SectionInformation.ConfigSource);
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sectionName"></param>
 /// <param name="section"></param>
 /// <param name="data"></param>
 public static void SaveSection(string sectionName, SerializableConfigurationSection section, SqlConfigurationData data)
 {
     if (!string.IsNullOrEmpty(sectionName))
     {
         SqlConfigurationManager.PrepareConfigSystem(data);
         SqlConfigurationManager.configSystem.SaveSection(sectionName, section);
     }
 }