Hi Experts,

I am searching for a way to edit web.config connection strings using .msi file. Since it needs to be installed by other people. I dont want others to explicitly go into file and edit the server address and db username and password.

I want to have a nice interface or an .msi file would be a very good option. Can someone guide me with a starting point on this issue.

Your help is highly appreciated.

5 Years
Discussion Span
Last Post by newuser17

If you use a tool (like InstallShield) you can just add a dialog where they input the data, and you can write it to the file in script. You just need to find a tool that you are comfortable with.


I was able to resolve partially by using this function

System.Configuration.Configuration config = null;
config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/ApplicationVirtualPath");
//Application virtual path can be found thru IIS properties of that application

Resolved. The idea is to use the above blog and instead of openexeconfiguration use the above statement, and try to split the string. You should be able to resolve.


 public override void Install(System.Collections.IDictionary stateSaver)


            string strServer, strUser;

            strServer = Context.Parameters["targetdir"].Split('/')[0];
            //MessageBox.Show("strserver" + strServer);

            strUser = Context.Parameters["targetdir"].Split('/')[1];
            //MessageBox.Show("strUser" + strUser);
            //you can similarly add for password and etc if you are building a connection string

            Context.Parameters["targetdir"] = strServer;

            Context.Parameters["User"] = strUser.Split('=')[1];
            //you can add for password etc similarly

            System.Configuration.Configuration config = null;

            config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Virtual Directory");

            //eg: user id=;password=;data source=;initial catalog=;Network Library=
            // reconstructing the above mentioned string for value of connection string
            String _connectionStringValue = "user id=" + Context.Parameters["User"] + "; password= " + Context.Parameters["Passwd"] + "; data source= " + Context.Parameters["DataSource"] + ";initial catalog=;Network Library=";
            //Editing config values
            config.AppSettings.Settings["Param1"].Value = _connectionStringValue;
            //MessageBox.Show("Param1: " + config.AppSettings.Settings["Param1"].Value);

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.