Wednesday, April 21, 2010

Reading & Writing connection strings app.config

Reading the connection string:
ConfigurationManager.ConnectionStrings["Connection Name"].ConnectionString

Writing the connection string:
// get the config file for this application
Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None );

// set the new values
config.ConnectionStrings.ConnectionStrings["Connection Name"].ConnectionString = "Connection String Value";

// save and refresh the config file
config.Save( ConfigurationSaveMode.Minimal );
ConfigurationManager.RefreshSection( "connectionStrings" );

อ้างอิง

No comments:

Post a Comment

Popular Posts