もちろん、カスタム構成セクションを好きなだけ作成することを妨げるものは何もありません。
次のようなものを試してください。
<?xml version="1.0"?>
<configuration>
<!-- define the config sections (and possibly section groups) you want in your config file -->
<configSections>
<section name="SqlConnection" type="System.Configuration.NameValueSectionHandler"/>
<section name="PacConnection" type="System.Configuration.NameValueSectionHandler"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<!-- "implement" those config sections as defined above -->
<SqlConnection>
<add key="abc" value="123" />
</SqlConnection>
<PacConnection>
<add key="abc" value="234" />
</PacConnection>
</configuration>
は、エントリ(など)System.Configuration.NameValueSectionHandler
を含む構成セクションに使用するデフォルトのタイプです。<add key="...." value="....." />
<appSettings>
値を取得するには、次のようなものを使用します。
NameValueCollection sqlConnConfig = ConfigurationManager.GetSection("SqlConnection") as NameValueCollection;
string valueForAbc = sqlConnConfig["abc"];
また、.NETで定義されている既存のセクションハンドラータイプと、独自のカスタム構成セクションを自分で定義している場合は、それらを完全に組み合わせることができます。必要なものを使用してください。