finally, i have the solution and it works
so as I said before I encrypt my connectionstring elsewhere with an Encrypt() function then I put the encrypted string in Place of my old connectionstring of APP.CONFIG
<pre><?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Benificiare.Properties.Settings.LogementConnectionString" connectionString="6uDB/32KxMOEPPO0maQDJ63Adjp7okmRdGd9s67mV5+8v6wiRK8UKWscnJSbQzFZTQCLiHQnZPGC8S6lI5Uw28qgjKLL14bkL8sNaDkwRUZ+bB6GMFelH9OVZpG1p+4T/I1LosmrkHylQKHotPFZg3xq3EwDJOY3rjbgE5mu6ow=" providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>
THE NAME OF CONNECTION IS
Benificiare.Properties.Settings.LogementConnectionString
and the encrypted chaine is
"Benificiare.Properties.Settings.LogementConnectionString" connectionString="6uDB/32KxMOEPPO0maQDJ63Adjp7okmRdGd9s67mV5+8v6wiRK8UKWscnJSbQzFZTQCLiHQnZPGC8S6lI5Uw28qgjKLL14bkL8sNaDkwRUZ+bB6GMFelH9OVZpG1p+4T/I1LosmrkHylQKHotPFZg3xq3EwDJOY3rjbgE5mu6ow="
when the app is running i have to decrypt this one and use the decrypted as a connectionstringg of my app so what i did is
Configuration configuration = ConfigurationManager.OpenExeConfiguration(@".\Myapp.exe");
connection = ConfigurationManager.ConnectionStrings["Benificiare.Properties.Settings.LogementConnectionString"].ConnectionString;
string ENC = DecryptString(connection, "KEY");
configuration.ConnectionStrings.ConnectionStrings["Benificiare.Properties.Settings.LogementConnectionString"].ConnectionString = ENC;
so what i have to do, is to change the last instruction with
var settings = ConfigurationManager.ConnectionStrings["Benificiare.Properties.Settings.LogementConnectionString"];
var field = typeof(ConfigurationElement).GetField( "_bReadOnly", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
field.SetValue(settings, false);
settings.ConnectionString = ENC;
and it works pefectly