我已将我的 ConnectionString 移动到用户设置中
<userSettings>
<FrontEnd_Offline.Properties.Settings>
<setting name="PC_Name" serializeAs="String">
<value>PC-CARTO3</value>
</setting>
<setting name="Soft8Exp_ClientConnStr" serializeAs="String">
<value>Data Source=xxxx;Initial Catalog=xxx;User ID=xx;Password=xxx</value>
</setting>
并用这个保存修改
private string BuildConnection()
{
if (String.IsNullOrEmpty(cmbServers.Text))
return "";
SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
csb.DataSource = cmbServers.Text;
//csb.IntegratedSecurity = chkUseWindowsSecurity.Checked;
csb.InitialCatalog = "xxxx";
csb.UserID = "xx";
csb.Password = "xxxx";
string cs = csb.ToString();
return cs;
}
private void simpleButton_ServeurSave_Click(object sender, EventArgs e)
{
string Temp_CS = BuildConnection();
if (!String.IsNullOrWhiteSpace(Temp_CS))
{
SqlConnection con = new SqlConnection(Temp_CS);
try
{
//set the new value of ClientConnectionString
Properties.Settings.Default.Soft8Exp_ClientConnectionString = Temp_CS;
Properties.Settings.Default.Soft8Exp_ClientConnStr = Temp_CS;
//apply the changes to the settings file
Properties.Settings.Default.Save();
}
catch (Exception ex)
{
MessageBox.Show("Impossible de se connecter à la base de données\n" + ex.Message, "Result", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
它工作正常。现在我想对我的实体连接做同样的事情。我知道我必须使用实体 connectionBuilder,但问题是:我无法将实体的 connectionString 移动到 userSetting 中。
提前谢谢你