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): .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 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 advanced.


Consider that the connection information may change at any point in the application's lifespan. Because of this, installation time is not the best location for this to occur.

Most commonly, you'll want to prompt the user for this information at startup if it is not already present, or if it is present but connection/login fails (with an appropriate error message). Upon successful login, store the information in the registry or whichever app config data solution you're using. You may also want to look at encrypting this data for security purposes, if you think that clients will be using per-user authentication.

| improve this answer | |
  • Marc, I'm thinking of encrypting the connection string after saving it to app.config. My problem is how the user will enter the connection string data initially. My main concern is if the admin wants to use SQL authentication which means he has to give username and password to the user to enter. – anon2009 Dec 28 '09 at 15:48
  • Hm. Perhaps an auto-config option, where the client enters the name of a server (provided by the admin), which in turn does nothing but provide the necessary credentials? That way, the only thing you're storing locally is the hostname of that server. This also gives flexibility in terms of changing DB server connection info (including expired passwords, etc). – Marc Paradise Dec 28 '09 at 16:18
  • Marc, This can be achieved with a web service that the app calls to get the connection string. I thought of doing exactly that, but installing a web service creates more work for the admin to maintain, who he has to find an available web server, run a separate installer to create a web site tohost the web service. – anon2009 Dec 28 '09 at 16:49
  • It sounds like you already have a server component for this, or is it just the database that resides on the server? If you do already have a server component, then could you modify that to include this service? It need not be as heavy as a web service - a simple socket listener/response could do it. – Marc Paradise Dec 28 '09 at 17:07
  • Marc, The database resides on the server and without it the app can do nothing. Basically is pulling data from the db as its main feature. I don;t know if sockets is a good solution. Too many security issues. Don't forget this is a down-loadable product. – anon2009 Dec 28 '09 at 18:09

Store the connection string in the app.config encrypted, you can use your own encryption or the configuration classes in .Net have encryption methods built in. Make sure you use something besides the default machine encryption so the admin could create a config file and use that on his/her local network install.

Like Marc says check on start up if there is a valid connection if not prompt the user for connection method. The local admin can run the app create the config settings and deploy them from there.


| improve this answer | |
  • boezo, Can you please explain to me how an admin can create the config settings and deploy from the network, when the application must be installed in the user's local box? – anon2009 Dec 28 '09 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy