Another alternative to doing this is also using a hack
to change the read-only parameter ConfigurationManager.ConnectionStrings
, this solution found on the website http://david.gardiner.net.au/, being like this:
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 was giving the error Keyword not supported: “data source”
, to fix it just change where you have "
in the connection string for single quotes.
Remembering that it is a hack
, however I did several tests here and the application is working normally.
Are you familiar with the Pattern Singleton design? Do you know how to leave your Singleton thread safes classes (ensures uniqueness in different threads)? if you know everything just implement if you do not know comments here that I create an example for you!
– Felipe Assunção
Thank you @Felipeasunción for the comment, if you can post an example I thank you, thank you.
– henriquedpereira
I added an answer
– Felipe Assunção