Saving SqlConfigurationSection to configuration source

Topics: Enterprise Library Core, General discussion
Apr 1, 2009 at 2:25 PM
I am trying to use SQL server to save and retrieve configuration information. I added a SQL Configuration source to the Configuration Sources in the Enterprise Library Configuration designer.
I have set the connection string and the Get, Set, Remove and Refresh stored procedures in the properties of this SqlConfigurationSource in the designer.
I am then trying to programmatically set a value using code (in an nunit test at first) using the code below.
My question is what do I pass to the first parameter of configurationSource.Add? It wants an IConfigurationParameter, and I can seemingly create a SqlConfigurationParameter but I have two problems with this, firstly i have to hardcode reliance on SqlConfigurationParameter rather than using the IConfigurationParameter interface, and secondly if I did that I would have to pass it all the database connection/stored procedure info again when the SqlConfigurationSource has already got this information, so it seems a bit nonsensical to specify it twice. What is the correct resolution of this?

public void SaveAndRetrieveInt()
var serializableConfigurationSection = new NamedSerializableConfigurationSection {Name = "TestInteger", Value = 42};
var configurationSource = ConfigurationSourceFactory.Create("Sql Configuration Source");
configurationSource.Add( ???



public class NamedSerializableConfigurationSection : SerializableConfigurationSection
public string Name
get{ return (string) base["Name"];}
set { base["Name"] = value;}

public int Value
get{ return (int) base["Value"];}
set { base["Value"] = value;}

Apr 2, 2009 at 9:03 AM

Actually I'm not sure about this one. But I looked at the Unit test for SqlConfigurationSource and it seems that it do pass the database info twice, one for the SqlConfigurationSource and one for the parameter. Maybe you can have a look, You can find it in <Install Dir>\EntLib4Src\Quick Starts\SqlConfiguration\UnitTests\ .

Valiant Dudan
Global Technology & Solutions
Avanade, Inc.
Apr 2, 2009 at 10:25 AM
it seems that adding the following method to SqlConfigurationSource (and IConfigurationSource) works:

       /// <summary>
        /// </summary>
        /// <param name="sectionName"></param>
        /// <param name="configurationSection"></param>
        public void Add(string sectionName, ConfigurationSection configurationSection)
            if (!(configurationSection is SerializableConfigurationSection))
                throw new ArgumentException(string.Format(Resources.Culture, Resources.ExceptionUnexpectedType, typeof(SerializableConfigurationSection).Name), "configurationSection");

            SerializableConfigurationSection serializableSection =
                configurationSection as SerializableConfigurationSection;
            Save(data.ConnectionString, data.SetStoredProcedure, sectionName, serializableSection);

would there be any merit in me submitting this as a patch?

Jan 28, 2010 at 5:55 PM
Edited Jan 28, 2010 at 6:38 PM

I just downloaded the lastest files, and noticed this suggestion has not been acted on.  I was wondering if it's been missed, or there was some basis for it not being added.


Jan 29, 2010 at 1:16 AM

We'll ask the EntLib team about this.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.