views:

448

answers:

1

Hi there,

I've battled with modifying Configuration settings in the App.config file in the past, and gave up any hope of making it work. Now again, I find myself in the same shoes, but this time determined to sort it out!

The application Im creating is a WindowsForms .NET 3.5 (SP1) app. It is to be used in a closed, networked environment. It is not a SmartClient app, but an "always-connected" one, and transacts over the local network with a central database server.

The app works fine, and now that Im ready to deploy and create the setup files, I must ask 2 very important questions:

  1. How do I (especially!) 'modify' the ConnectionString value from the Setup Wizards? ;and
  2. How/where do/should I encrypt this value?

This is surely something every developer goes thru when moving from development to production, and I would sincerely appreciate any help.

Thank you!

+1  A: 

This question provides good information on how to modify the configuration file (in general) during setup.

Julien Poulin
Thanks Julien! Tell me, would it preferrable to use Click-Once Deployment for my scenario? - There is a central server which is used for a SQL Server 2008 database. On this server is also a web app for admin login only. Should I use COD and let users install the app from a "public" page within this web app? And if so, can I not customize the COD to install and simultaneously modify the connString in the app.Config?
Shalan
Sorry, I have no experience with Click-Once Deployment
Julien Poulin
So let me understand this correctly...I know that the "app.config" is read-only at *runtime* and therefore cannot be modified. 2 things arise from this - (1) its possible to 'swap out' the app.config with a modified one ready for production, but that seems like a hassle. (2) by linking the main config to a secondary one, the latter CAN be modified at runtime...am I correct? If this is so, then I can either popup a small dialog prompting input or write it during install (the latter seems better i.t.o. security)Your thoughts???
Shalan
Sorry, I didnt see your reply when I posted my 2nd one! Its cool, you've at least helped me (thru your link) in making me think of something else, more regarding COD. I think I shall ask that as a separate question so as not to confuse with this topic.Your opinion also, as another developer, would it not be more advisable to have the modified config persisted to the user upon installation rather than allow the user to change this after installation (at runtime)?
Shalan
It depends of what you mean by 'read-only at runtime'. You *can* modify the [AppName].exe.config file at runtime and refresh it in your application, but you can't modify the app.config file while your application is in debug mode in VS.
Julien Poulin
If you really need the info to start the application, then it makes sense to ask them during setup, especially if they never change. However, if the user might have to change the information later on, it would be a good idea to provide a way to modify them later (e.g. if user makes a mistake), via an option dialog in your application for instance. HTH
Julien Poulin