Link to home
Start Free TrialLog in
Avatar of milani_lucie
milani_lucieFlag for United States of America

asked on

"Click Once" deployment - Changing Configuration File Settings - C# / VB.NET


I have done "Click Once" deployment of my application written in C# / VB.NET. Now i want to change the configuration file settings (Ex: Connection String). I do NOT want to do whole deployment once again, because it is a simple configuration setting. And if i change the configuration settings directly, will it work ? Can you please provide me which file i need to touch, .NET commands & steps for dealing with this situation ?

Avatar of ukerandi
Flag of United Kingdom of Great Britain and Northern Ireland image

.NET Framework 2.0 added a separate configuration section in both Windows Application configuration (App.config) and Web Application configuration (Web.config) file. Developers can use these section to store connection string information such as a connection string name or provider type etc. In the following tutorial I will show you how you can store and retrieve connection string information in .NET Windows Application using C#.
The following code shows how you can store connection strings in App.config file.

<?xml version="1.0" encoding="utf-8" ?>
      <add name="MyDBConnectionString" providerName="System.Data.SqlClient"
            connectionString="Data Source=localhost;Initial Catalog=MySQLServerDB; Integrated Security=true" />
Once you have saved your connection string in App.config file you can use System.Configuration.ConfigurationManager class to read this connection string in code.

ConnectionStringSettings  conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
ConnectionStringsSettings class provides properties to read connection string settings in your program as following code shows.

string name = conSettings.Name;
string providerName = conSettings.ProviderName;
string connectionString = conSettings.ConnectionString;
Avatar of Anuradha Goli
Anuradha Goli
Flag of Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Which file you need to amend really depends the initial configuration. Whether the initial programmer used application settings or whatever method for connection string.

If he/she used the application settings, then changing just the connection string there will work.
If you want to change settings for every user from your server, then you will have to redeploy the app. If you want to change settings on the client machines manually, you would need to find out the folder path of click once app from its shortcut, and then go in and change the appname.exe.config file.
Avatar of milani_lucie


Not exactly what i want...