Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference connection strings in separate config file

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?

like image 273
Simon Avatar asked Feb 27 '26 16:02

Simon


1 Answers

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.

like image 179
Baral Avatar answered Mar 02 '26 06:03

Baral



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!