2
Answers

Add new connection string to your web application:

Roshdy Abuzeid

Roshdy Abuzeid

15y
2.8k
1


this topic about adding new connection string to the application at run time.

the user will fill the (connection name, machine name or IP, database name, login ID, login password)


Add this code to the button  event handler:

string connectionStringName = txtNewConn.Text;
                string connectionString = "Password=" + txtPassword.Text + ";Persist Security Info=True;User ID=" + txtUserLogin.Text + ";Initial Catalog=" + txtDBName.Text + ";Data Source=" + txtIP.Text;

                ConnectionStringSettings Settings = new ConnectionStringSettings(connectionStringName, connectionString);
                Settings.ProviderName = "System.Data.SqlClient";

                var cfg = WebConfigurationManager.OpenWebConfiguration(@"/");
                cfg.ConnectionStrings.ConnectionStrings.Add(Settings);

                cfg.Save();
Answers (2)