1

I have an app.config file in Winforms application that holds a connection string. This is to go out to multiple tenant (clients) as a separate file. These clients have different database sources. This config file also holds other version information such as EF, Telerik reporting etc...

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />

and

<section name="Telerik.Reporting"  
         type="Telerik.Reporting.Configuration.ReportingConfigurationSection, Telerik.Reporting, Version=8.1.14.804, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" 
         allowLocation="true" allowDefinition="Everywhere" />

The problem I have is when we have an updated version of EF or Telerik reporting with our application and we deploy (auto-deploy) this we need to overwrite the app.config file in the client directory to update the versions in the client config file. They then lose their connection setting and I do not want the client to have to go and re-enter it.

My question:

Is there a best practice to overcome this issue? Should I hold the connection string somewhere else?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user631618
  • 33
  • 5

3 Answers3

4

Yep, the best thing to do is to move your connection strings section to an another config file and reference that file within your app.config.

For example create a new file called connectionStrings.config:

<connectionStrings>
  <add name="Default" connectionString="[client_connection_string] "/>  
</connectionStrings>

And in your app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings configSource="connectionStrings.config" />  
</configuration>

A full example can be found here.

Teppic
  • 2,506
  • 20
  • 26
1

Use an external configuration file that is referenced from the application config file. E.g. include this section in your config file.

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

The external config file is described http://msdn.microsoft.com/en-us/library/ms254494(v=vs.110).aspx

Note that storing connection settings in plaintext on a workstation is still a bad idea.

Using Windows registry for stuff like this is a definite no-no these days.

Gary Walker
  • 8,831
  • 3
  • 19
  • 41
0

you can try to hold all connection data that you need in separate xml file so it dont get overwrite when you preform a deploy of updated version.

Max
  • 156
  • 9