How to change the app.config file at runtime?

Asked

Viewed 828 times

1

how can I change the app.config file at runtime?

I want to change the connection string:

<add name="WiconEstoqueDataContextConnectionString" connectionString="User Id=USER;Password=PASS;Host=HOST;Database=wicon_estoque;Persist Security Info=True" />

1 answer

4


Hello, try this on:

var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings");
connectionStringsSection.ConnectionStrings["WiconEstoqueDataContextConnectionString"].ConnectionString = "sua nova conexão";
config.Save();
ConfigurationManager.RefreshSection("connectionStrings");

I hope this can help you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.