7

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.

VansFannel
  • 45,055
  • 107
  • 359
  • 626
  • Look up "Add as Link" and "Shared Project". The latter is how I share most of my code, ie you add a third project and reference it from the other two. If you have a case where the shared project needs to compile on its own (say to generate code), then you can create a separate project and reference its files by adding them as "links" within each project – flakes Oct 06 '17 at 06:17
  • 3
    Possible duplicate of [Centralize connection strings for multiple projects within the same solution](https://stackoverflow.com/questions/16154684/centralize-connection-strings-for-multiple-projects-within-the-same-solution) – mmushtaq Oct 06 '17 at 06:26
  • [Managing Multiple Configuration File Environments with Pre-Build Events](https://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx) can be helpful for you. – mmushtaq Oct 06 '17 at 06:27
  • I've worked on a solution where a lookup service was implemented which stored platform configuration information such as other endpoints and connection strings. – Quality Catalyst Oct 06 '17 at 06:30

1 Answers1

0

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

Mr Slim
  • 1,458
  • 3
  • 17
  • 28