Wayne Molina
Wayne Molina

Reputation: 19586

Is it possible to override both appSettings and connectionStrings in a Local.config file?

We presently override appSettings from our web.config in a Local.config file for each developer. However we also need to override connection strings, so we access our local copy on our machine while the web.config might reference the production server. I know that you can override appSettings by specifying file="Local.config", but is this possible for the connectionStrings as well? We already make use of an external file for the connection strings but this file has all three connection strings (local developer, dev, and production).

What I'd like to do is have the connectionString defaulted to production, but overridden on a developer's machine and on the development server. However, this doesn't seem to be possible as unlike appSettings, you can't specify a value for connectionStrings when you tell it to use an external file.

Is this possible to achieve without having to add additional code?

I should note that I cannot use the Config Transformations at the moment as we are on ASP.NET 3.5.

Upvotes: 1

Views: 1101

Answers (1)

DotNetFreak
DotNetFreak

Reputation: 176

In the main application configuration file, you use the configSource attribute to specify the fully qualified name and location of the external file. This example refers to an external configuration file named connections.config.

<?xml version='1.0' encoding='utf-8'?>
<configuration>
    <connectionStrings configSource="connections.config"/>
</configuration>

For detailed information, please visit this link on msdn (section: Using External Configuration Files)

Upvotes: 1

Related Questions