You can split connection strings between several projects in a solution as follows:
Create a ConnectionStrings.config file with connection strings in the solution folder, this file should contain only the connectionStrings section
In your projects, add this configuration file as a link (add an existing item, add as a link)
- Select the added file and set its
Copy to Output Directory property Copy to Output Directory Copy always or Copy if newer - In the
App.config your projects, specify the associated ConnectionStrings.config file using the configSource attribute: <connectionStrings configSource="ConnectionStrings.config" />
ConnectionStrings.config
<connectionStrings> <add name="myConnStr" connectionString="Data Source=(local); Initial Catalog=MyDB;Integrated Security=SSPI;" providerName="System.Data.SqlClient" /> </connectionStrings>
App.config
<?xml version="1.0" encoding="utf-8" ?> <configuration> ... <connectionStrings configSource="ConnectionStrings.config" /> ... </configuration>
More details ...
source share