我試圖改變連接字符串,但它只是在內存中的變化,而不是在app.config文件,下面是我使用更改連接字符串
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings[1].ConnectionString = "metadata=res://*/TCSModel.csdl|res://*/TCSModel.ssdl|res://*/TCSModel.msl;provider=System.Data.SqlClient;provider connection string='Data Source=" + cmbServerName.Text + ";Initial Catalog=" + cmbDatabase.Text + ";User ID=" + txtUserName.Text.Trim() + ";Password=" + txtPassword.Password + ";Persist Security Info=True;MultipleActiveResultSets=True'";
config.ConnectionStrings.ConnectionStrings[1].Name = "TCSEntities";
config.ConnectionStrings.ConnectionStrings[1].ProviderName = "System.Data.EntityClient";
config.Save(ConfigurationSaveMode.Full, true);
ConfigurationManager.RefreshSection("connectionStrings");
代碼時丟失或上面的代碼錯了?