Hi I have a build server set up with various deployements, DEV, QA, PRODUCTION. The build server sets up my default connection string based on the enviroment by modifying the app.config file. The app.config file with the connection strings is located in a different a project then my main startup project, so the structure is something like:
Main Startup Project
-app.config(nothing of use here)
DataAccessLayer
-app.config(with my connection strings)
-Properties
Settings.Settings
-Settings.Designer.cs
When I create the original connection string at design time all, the connection string values get saved automagically by the vs2008 wizard in the app.config file as well as the settings.settings and the settings.designer files (3 different files)
I access the connection strings using properties.settings.default."defaultconnectionstring" , it seems to be using the settings stored in the actual designer.cs file becuase it I update that file manually I get the correct updated string, versus if I update the app.config or settings.settings file manually I don't get the updated connection string.
My question is if there is a way to synchronize the settings.settings files (both of them) to whatever is currently in the app.config file, alternatively is there a way I can read the actual app.config file for the dataAccessLayer project, I tried using the ConfigurationManager classConfigurationManager.AppSettings,ConfigurationManager.ConnectionStrings,ConfigurationManager.OpenExeConfiguration()
but I can't point it to the app.config of the dataaccesslayer project, I don't think dataaccesslayer app.config is even deployed anywhere I'm not sure how to specify to have it deployed with the rest of the project.
Maybe I'm approaching the solution completely incorrectly and there is another way to specify and read back the default connection string for various deployment environments, any suggestions are welcome.
THanks a lot.
Chris
| | derski Thursday, August 27, 2009 9:25 PM | Hello Chris, Thanks for your post on MSDN forum. I am not sure that I understanding you correctly. You want to synchronize the connection string in Application settings and app.config file. Please correct me if there is any misunderstanding. Based on my research, the typed data set, which is generated using the wizard, actually using the following code to set the connection string(might use a different setting name). this._connection.ConnectionString = global::Mycontrols.Properties.Settings.Default.NorthwindConnectionString; If we change the setting in the Application Settings designer, these three files are synchronized. If there is any difference between the Settings.Settings file and the app.config file, Visual Studio will throw an warning which says the connection string was changed in the app.config file when opening the Application Setting designer. Also, we should never change the Settings.designer.cs file, because this file is generated by a tool called SettingsSingleFileGenerator(see Property Window when selesting the Settings.Settings file). For example, if we save the Settings.Settings file in the designer, even there isn't any changes, the Settings.designer.cs is re-generated. Hope this helps. If you have any additional question, welcome to post here. Thanks, Rong-Chun Zhang MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Marked As Answer byRong-Chun ZhangMSFT, ModeratorWednesday, September 02, 2009 11:47 AM
- Edited byRong-Chun ZhangMSFT, ModeratorFriday, August 28, 2009 11:42 AMtypo
-
| | Rong-Chun Zhang Friday, August 28, 2009 11:40 AM | Cool,
Thanks a lot, thats good to know, I will definitely play around with that.
I actually opted to create all of my configuration files (settings.settings file)separately and then keep only a single flag in my main project telling my program which configuratin should be used. I think this is a lot cleaner, I can compile all my settings into the cs file and its easy to see what the settings for various deployement are rather then having the settings massaged in the back by some build script. My build server only has to set a single value in the main project app.config and from there my program will be pointed to the appropriate settings file. Then in my settings.setting file I can easily specifiy all the connection strings, the seed data scripts etc.
Thanks again.
Chris
- Marked As Answer byRong-Chun ZhangMSFT, ModeratorWednesday, September 02, 2009 11:47 AM
-
| | derski Tuesday, September 01, 2009 5:52 PM | Hello Chris, Thanks for your post on MSDN forum. I am not sure that I understanding you correctly. You want to synchronize the connection string in Application settings and app.config file. Please correct me if there is any misunderstanding. Based on my research, the typed data set, which is generated using the wizard, actually using the following code to set the connection string(might use a different setting name). this._connection.ConnectionString = global::Mycontrols.Properties.Settings.Default.NorthwindConnectionString; If we change the setting in the Application Settings designer, these three files are synchronized. If there is any difference between the Settings.Settings file and the app.config file, Visual Studio will throw an warning which says the connection string was changed in the app.config file when opening the Application Setting designer. Also, we should never change the Settings.designer.cs file, because this file is generated by a tool called SettingsSingleFileGenerator(see Property Window when selesting the Settings.Settings file). For example, if we save the Settings.Settings file in the designer, even there isn't any changes, the Settings.designer.cs is re-generated. Hope this helps. If you have any additional question, welcome to post here. Thanks, Rong-Chun Zhang MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Marked As Answer byRong-Chun ZhangMSFT, ModeratorWednesday, September 02, 2009 11:47 AM
- Edited byRong-Chun ZhangMSFT, ModeratorFriday, August 28, 2009 11:42 AMtypo
-
| | Rong-Chun Zhang Friday, August 28, 2009 11:40 AM | Thanks for the reply,
Yes I do want to synchronize the connection string in the app.config and the application settings. Also I am essentially using theglobal::Mycontrols.Properties.Settings.Default.NorthwindConnectionString method to read my connection string. The problem is that I can't edit the application settings in the visual studio desinger. My build server sets the settings based on the deployment environment. so my connection string points may point to server A, or server B or server C. So my build server will run an xml parser which will change the app.config and settings.settings file butSettings.designer.cs does not get regenerated properly and usingglobal::Mycontrols.Properties.Settings.Default.NorthwindConnectionString points to the unapdated string.
I will try to find out if I can run thatSettingsSingleFileGenerator from the build server which I imagine should solve the problem.
Thanks again,
Chris | | derski Friday, August 28, 2009 4:18 PM | Hello Chris, The SettingsSingleFileGenerator is not a command line tool, it is a code generator class in the Microsoft.VisualStudio.Editors assembly. You can try to write a tool to call this class to generate the code you want. http://www.dotnettech.net/BCL/CSharp/Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator/Class.aspxThanks Rong-Chun Zhang MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. | | Rong-Chun Zhang Tuesday, September 01, 2009 10:51 AM | Cool,
Thanks a lot, thats good to know, I will definitely play around with that.
I actually opted to create all of my configuration files (settings.settings file)separately and then keep only a single flag in my main project telling my program which configuratin should be used. I think this is a lot cleaner, I can compile all my settings into the cs file and its easy to see what the settings for various deployement are rather then having the settings massaged in the back by some build script. My build server only has to set a single value in the main project app.config and from there my program will be pointed to the appropriate settings file. Then in my settings.setting file I can easily specifiy all the connection strings, the seed data scripts etc.
Thanks again.
Chris
- Marked As Answer byRong-Chun ZhangMSFT, ModeratorWednesday, September 02, 2009 11:47 AM
-
| | derski Tuesday, September 01, 2009 5:52 PM | I have a similar problem, but I thought this might be best placed in this thread.
My problem is that I have my project as a class library, so when I compile the code it generates an <assembly>.dll and an <assembly>.dll.config. I create a new project (web or application) that references this assembly. The dlls get copied to the bin when I build the new project, but the dll.config does not. I copy the dll.config over to the bin, and make my modifications to the config file. When it comes time to run the application the dll doesn't seem to be accepting the changed values in the config file rendering the config file useless.
How can I make the changes to the config file so that it is referencing the changed values? In code, I am calling:
using <namespace>.Properties;
string myStringSetting = Settings.Default.MyStringSetting;
have also noticed in the Designer.cs file that the Settings has aglobal::System.Configuration.DefaultSettingValueAttribute to set the value initially (possibly in case there isn't a config file to set it). But it is not getting the values from the config file.
Any help is much appreciated.
Thanks in advance, Jon | | CrazyEnigma Friday, September 25, 2009 8:28 PM | Hello Jon, I've test it on Visual Studio 2008 and the settings for dll project is merged to the settings for executable project. However, the following article might give some help. http://blogs.msdn.com/nickmalik/archive/2004/11/25/270420.aspxSince this is a new question, I recommend you create a new thread to post this question. Thanks, Rong-Chun Zhang MSDN Subscriber Support in Forum If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. | | Rong-Chun Zhang Wednesday, September 30, 2009 11:20 AM |
|