+1  A: 

Hi,

Well for a simple value, you are best placing that <dataConfiguration /> into the <appSettings /> section as a key-value pair:

<appSettings>
    <add key="defaultDatabase" value="foo" />
</appSettings>

If you want to have a custom configuration section, then you need to inherit various classes to conform to the Configuration API.

Here are some tutorials:

http://msdn.microsoft.com/en-us/library/2tw134k3.aspx http://www.codeproject.com/KB/cs/CustomConfigurationSectio.aspx

And here is a link to a Visual Studio configuration section designer tool:

http://csd.codeplex.com/

Alternatively, but not advised, you could just read it in as an XML document and parse the value out.

Personally, I'd go for the app settings route.

Adam
+1  A: 

This is how I have done it in the past:

using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration;

DatabaseSettings dbSettings = (DatabaseSettings)ConfigurationManager.GetSection("dataConfiguration");
string connectionString = ConfigurationManager.ConnectionStrings[dbSettings.DefaultDatabase].ConnectionString;
Daniel Dyson
+1 - I was about to break out some code using ConfigurationManager.GetSection, and hadn't spotted that this is actually a config block from the enterprise library.
Rob Levine