Add a connection string to app.config runtime


Add the System.Configuration reference to your project.

Using this namespace in your code.

And use this code segment to add the new connection string:

Configuration myConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
myConfig.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("ConnStr1", strConn));
myConfig.Save();

Posted on 12:14 by csharper and filed under , , , | 0 Comments »

0 comments:

Post a Comment