Another alternative to doing this is also using hack
to change the read-only parameter ConfigurationManager.ConnectionStrings
, this solution found on the link , thus:
var settings = ConfigurationManager.ConnectionStrings["nomeDaMinhaConexao"];
var fi = typeof(ConfigurationElement).GetField("_bReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
fi.SetValue(settings, false);
settings.ConnectionString = "minhaStringDeConexao";
I put the connection string and it was giving the error Keyword not supported: “data source”
, to correct it is just to change where it has "
in the connection string for single quotation marks.
Remembering that it's a hack
, but I've done a lot of testing here and the application is working normally.