Connection string during installation
I've been convinced to use windows setup files(msi) for the installation of my new windows forms application after I asked a question here and got some excellent answers (thank you all): https://serverfault.com/questions/97039/net-application-deployment
Now i have a different question:
My application will need to access a SQL Server to provide users with data, which means that the connection string must be stored 开发者_C百科in the client's app.config file.
How should I handle this?
During installation, the user enters the connection string to that database? How they get the connection string? In an email from the admin? What if the admin wants to use SQL authentication and need to put the user info at the connection string?
So you know, the app will be sold via the internet, so I don't have any access to the admins or the network.
Any suggestions?
Thanks in advance.
I think you should take a look at WiX 3.0 (wix.sourceforge.net) but prepared for a learning curve as you define your MSI completely in XML.
You can reverse engineer an existing MSI using dark.exe (part of WiX) to start.
Once you have got your basic installer working with fixed connection strings then you would use WiX to define a user interface for collecting the connection data. A custom action (CA) would then need to write this data out to the .config file as part of the installer. This has been done many times before, see;
wix custom dialog for config edit http://www.rrreese.com/Article/Show/WiX%20SQL
Don't do it in the install - do it the first time the app runs and allow changes later. Doing it from the MSI can be non-trivial. Running this from the app is more debuggable and less error-prone than running it from an impersonated or system account custom action. Having it error out during the install is also awkward. They can't complete the install if they can't connect, and if you support silent install and entering the connection string via properties then you may fail silently with no way to tell the user. These are just some of the potentil issues. If you do it from the app the users can change their minds about how they connect, credentials etc, and other details of the connection string at any time without re-installing the app.
精彩评论