C# Class Library - Updating Application Settings
-
Looking for a workaround :rolleyes: ......I'm trying to update the settings file for a C# class library at runtime. Specifically, I'm trying to update the connectionstring setting for my typed datasets. Microsoft officially doesn't support this functionality in C# (click here) "Because there is no configuration file model for class libraries, application settings do not apply for Class Library projects. The exception is a Visual Studio Tools for Office DLL project, which can have a configuration file." I could create a custom config file but how do I get my typed datasets to reference it?? Thanks, Kevin
-
Looking for a workaround :rolleyes: ......I'm trying to update the settings file for a C# class library at runtime. Specifically, I'm trying to update the connectionstring setting for my typed datasets. Microsoft officially doesn't support this functionality in C# (click here) "Because there is no configuration file model for class libraries, application settings do not apply for Class Library projects. The exception is a Visual Studio Tools for Office DLL project, which can have a configuration file." I could create a custom config file but how do I get my typed datasets to reference it?? Thanks, Kevin
you can always create an XmlDocument object and load up the settings file and make the changes manually. For web applications I know there's a way to change the config file but I'm not sure if it will work in your case. Here's how I did it for my web application:
Configuration config = ConfigurationManager.OpenExeConfiguration(""); ConfigurationSection section = config.Sections["connectionStrings"]; // you can use the section information here such as // section.SectionInformation.UnprotectSection(); // then make sure to save the changes to the file config.Save();
and that's it---- www.digitalGetto.com
-
you can always create an XmlDocument object and load up the settings file and make the changes manually. For web applications I know there's a way to change the config file but I'm not sure if it will work in your case. Here's how I did it for my web application:
Configuration config = ConfigurationManager.OpenExeConfiguration(""); ConfigurationSection section = config.Sections["connectionStrings"]; // you can use the section information here such as // section.SectionInformation.UnprotectSection(); // then make sure to save the changes to the file config.Save();
and that's it---- www.digitalGetto.com
Thanks for the reply, but that isn't really what I'm looking for. I'm familiar with web configs and the configuration manager. My problem relates to C# class libraries. They don't allow the settings file to be modified at runtime and my typed datasets use the application settings file to determine the connection string. I would like to dynamically set the connection string property based on the application environment at runtime. Cheers.