sir, How to connect another serever after make setup file of that code in c# for windows application
private void button1_Click(object sender, EventArgs e)
{
Modify(txtName.Text, txtServer.Text, txtDataBase.Text, txtUID.Text, txtPassword.Text);
}
public void Modify(string name, string server, string dataBase, string uId, string password)
{
string ApplicationPath = Application.StartupPath;
string YourPath = Path.GetDirectoryName(ApplicationPath);
bool isNew = false;
string path = Path.GetDirectoryName(YourPath) + "\\App.config";
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNodeList list = doc.DocumentElement.SelectNodes(string.Format("connectionStrings/add[@name='{0}']", name));
XmlNode node;
isNew = list.Count == 0;
if (isNew)
{
node = doc.CreateNode(XmlNodeType.Element, "add", null);
XmlAttribute attribute = doc.CreateAttribute("name");
attribute.Value = name;
node.Attributes.Append(attribute);
attribute = doc.CreateAttribute("connectionString");
attribute.Value = "";
node.Attributes.Append(attribute);
attribute = doc.CreateAttribute("providerName");
attribute.Value = "System.Data.SqlClient";
node.Attributes.Append(attribute);
}
else
{
node = list[0];
}
string conString = node.Attributes["connectionString"].Value;
SqlConnectionStringBuilder conStringBuilder = new SqlConnectionStringBuilder(conString);
conStringBuilder.InitialCatalog = dataBase;
conStringBuilder.DataSource = server;
conStringBuilder.IntegratedSecurity = false;
conStringBuilder.UserID = uId;
conStringBuilder.Password = password;
node.Attributes["connectionString"].Value = conStringBuilder.ConnectionString;
if (isNew)
{
doc.DocumentElement.SelectNodes("connectionStrings")[0].AppendChild(node);
}
doc.Save(path);
}