3

I would like to move my connection strings from my web.config file to a file called ConnectionStrings.config, both files are in the root of my web application.

Web.Config

<configuration>
    <connectionStrings configSource="ConnectionStrings.config"/>
</configuration>

ConnectionStrings.Config

<configuration>
    <connectionStrings>
        <add name="myConnectionString" connectionString="*****" providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

But when I try and run this I get the following error

The format of a configSource file must be an element containing the name of the section. (C:\Your Application\ConnectionStrings.config line 2)

Any ideas?

1 Answer 1

9

Web.Config

 <connectionStrings configSource="ConnectionStrings.config" />

ConnectionStrings.config:

<?xml version="1.0" encoding="utf-8" ?>
<connectionStrings>
    <add name="name" connectionString="server=(local);database=db;user Id=usr;password=pass;timeout=0"></add>
</connectionStrings>

This is how (without the providerName) I do it and it works fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.