Share connection string between many applications

Viewed 238

I'm developing a solution with C# and .NET Framework 4.7.

The solution has a ASP.NET Web MVC application and a Windows Service. Both connect to the same database and now I'm using their configuration files to store.

Is there any other way to store the connection string that both application can use it?

I don't want to have duplicated the same information in two configuration files.

There are also another settings that I would like to share.

1 Answers

In my experience this can be achieved by placing you connection strings in machine.config instead of web.config

Here is an MS article which touches upon the subject

machine.config can be located under

C:\Windows\Microsoft.NET\

Then depending on 32 or 64 bit flavour and then framework version

Below is the path to 64bit v4

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config

IMPORTANT Be sure to backup your machine.config files BEFORE making changes

Related