Question: > 
> **Possible Duplicate:**  
> 
> [VS2005 C# Programmatically change connection string contained in app.config](https://stackoverflow.com/questions/63546/vs2005-c-sharp-programmatically-change-connection-string-contained-in-app-config) 
> 
> 
> 

I have created a WinForms project in my PC using C#, and would like to deploy the project to other pc's, but I need to change the connection string in the app.config in order to connect the sql sever database in other pc's, and I want the users to configure the connection string. 

How can I accomplish this?

Answer: 
Like others have said creating your own config file is the way to go. Here is some code that may help

Just create an app.config file in VS and put it in the same directory as dll. It will look something like this. 

```
    <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
       <appSettings>
        <add key="YourThing" value="Something" />
       </appSettings>
    </configuration>

```

Then you can load it lke this.

```
string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

        string configFile = System.IO.Path.Combine(appPath, "App.config");
        ExeConfigurationFileMap configFileMap = new ExeConfigurationFileMap();
        configFileMap.ExeConfigFilename = configFile;

        System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);

```

You can then read values like this. 

```
config.AppSettings.Settings["YourThing"].Value;

```

And Save Values like this.

```
config.AppSettings.Settings["YourThing"].Value = "New Value";
config.Save();

```
Modify the app config from code.
<http://chiragrdarji.wordpress.com/2008/09/25/how-to-change-appconfig-file-run-time-using-c/>