This is my first WinForm application using the Entity Framework and I have to be able to update the connection string for the entity model I created on the fly and in my app.config file I have the following connectionString:
<add name="NCIPEntities" connectionString="metadata=res://*/NCIPModel.csdl|res://*/NCIPModel.ssdl|res://*/NCIPModel.msl;provider=System.Data.SQLite;provider connection string='data source="C:\Test\NCIP\NCIP.db3";pooling=True'" providerName="System.Data.EntityClient" />
This is what I wrote to update the string on the fly, it doesn't throw any errors when it runs but it also doesn't save the new connection string back to the app.config file.
private void UpdateEntityConnection()
{
StringBuilder Sb = new StringBuilder();
Sb.Append(@"metadata=res://*/NCIPModel.csdl|res://*/NCIPModel.ssdl|res://*/NCIPModel.msl;provider=System.Data.SQLite;provider""");
Sb.Append("connection string='data source=" + Settings.Default.Directory + "\\NCIP.db3;pooling=True'");
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings["NCIPEntities"].ConnectionString = Sb.ToString();
config.Save(ConfigurationSaveMode.Minimal);
ConfigurationManager.RefreshSection("connectionStrings");
}
Does anyone see what I am doing wrong because I don't.
Thanks.