How to Fix “configSource file ‘connections.config’ is also used in a parent” Error in ASP.NET IIS Deployment


2 views

This error occurs when IIS detects that a configuration file is being referenced at multiple levels in the application hierarchy. In this case, the connections.config file is being pulled into both:

  • The root application (vmsomething.com)
  • The virtual directory application (vmsomething.com/my_application_virtdir)

ASP.NET applications inherit configuration settings from parent applications in IIS. When you have:

<connectionStrings configSource="connections.config"/>

And this configuration exists at both the root and virtual directory level, IIS throws this conflict error because it cannot determine which configuration should take precedence.

Here are three approaches to resolve this:

<!-- Option 1: Remove configSource reference -->
<connectionStrings>
  <add name="server" connectionString="Data Source=OUR_DB_Server;..." providerName="System.Data.SqlClient"/>
</connectionStrings>

<!-- Option 2: Use distinct config file names -->
<connectionStrings configSource="connections_vdir.config"/>

<!-- Option 3: Clear parent configuration -->
<connectionStrings>
  <clear/>
  <add name="server" connectionString="Data Source=OUR_DB_Server;..." providerName="System.Data.SqlClient"/>
</connectionStrings>

Your admin should consider these IIS settings:

  1. Convert the virtual directory to an application in IIS Manager
  2. Set inheritInChildApplications="false" in root web.config
  3. Use location tags to restrict configuration scope

Here's a complete solution using the clear approach:

<configuration>
  <connectionStrings>
    <clear/>
    <remove name="server"/>
    <add name="server" connectionString="Data Source=OUR_DB_Server;Initial Catalog=MY_INITIAL_CATALOG;..."
         providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <!-- Rest of your configuration -->
</configuration>

This ensures your virtual directory application completely overrides any inherited connection strings.


When working with ASP.NET 4.0 applications in IIS 7.5, you might encounter a particularly frustrating configuration error:

The configSource file 'connections.config' is also used in a parent, this is not allowed.

This typically occurs when:

  • Your application is accessible through multiple URLs (root and virtual directory)
  • You're using external config files via configSource attribute
  • The IIS configuration has nested application hierarchies

In our case, the application exists at both:

D:\webs\myapplication (root)
D:\webs\myapplication\my_application_virtdir (virtual directory)

The web.config uses:

<connectionStrings configSource="connections.config"/>

While this works fine for the root application (http://vmsomething.com), it fails for the virtual directory path (http://vmsomething.com/my_application_virtdir).

ASP.NET prevents the same configSource file from being inherited in nested applications because:

  1. Configuration files are inherited by default in IIS
  2. The virtual directory is treated as a child application
  3. Having the same physical config file in both parent and child creates ambiguity

Here are three approaches to resolve this:

Solution 1: Unique Config File Names

Create separate config files for each application level:

Root web.config:
<connectionStrings configSource="connections.root.config"/>

Virtual directory web.config:
<connectionStrings configSource="connections.virtdir.config"/>

Solution 2: Convert Virtual Directory to Application

In IIS Manager:

  1. Right-click the virtual directory
  2. Select "Convert to Application"
  3. This breaks the inheritance chain

Solution 3: Remove configSource Inheritance

Modify the virtual directory's web.config:

<connectionStrings>
  <clear/>
  <add name="server" connectionString="..." providerName="System.Data.SqlClient"/>
</connectionStrings>

For production environments, I recommend this robust approach:

<connectionStrings>
  <clear/>
  <add name="server" 
       connectionString="Data Source=#{DB_SERVER}#;..." 
       providerName="System.Data.SqlClient"/>
</connectionStrings>

Then use Web.config transformations:

<connectionStrings xdt:Transform="Replace">
  <add name="server"
       connectionString="Data Source=PROD_DB_SERVER;..."
       providerName="System.Data.SqlClient"/>
</connectionStrings>

If you're still facing issues:

  1. Check file permissions on connections.config
  2. Verify the physical path in IIS matches your expectations
  3. Use Process Monitor to track file access attempts

Remember that configuration inheritance can be complex in IIS. Always test both application entry points after making changes.