How to retrieve the connection string from App.config from another project?

0

I have these connection strings in App.config from another project :

<connectionStrings>
   <add name="ConexaoTeste1" 
    connectionString="RGF0YSBTb3VyY2U9JCQkXFNRTEVYUFJFU1M7SW5pdGlhbCBDYXRhbG9nPXRlc3RlOw==" 
    providerName="System.Data.SqlClient"/>

   <add name="ConexaoTeste2" 
    connectionString="RGF0YSBTb3VyY2U9dGVzdGU7UGVyc2lzdCBTZWN1cml0eSBJbmZvPVRydWU7" 
    providerName="System.Data.OracleClient"/>
</connectionStrings>

This other project is not on my computer. It's in the network.

How do I redeem the value of ConexaoTeste2 in my project ?

    
asked by anonymous 23.03.2017 / 13:00

2 answers

1

Add reference System.Configuration to your project and do:

string conexao = 
    System.Configuration.ConfigurationManager.
    ConnectionStrings["ConexaoTeste2"].ConnectionString;

About the fact that App.config is remote: Here has a good reason not to do so, and also have some alternatives.

    
23.03.2017 / 13:34
0

I was able to solve the problem with the code below, ignoring the file as config and treating it as a normal xml, I ran the document, found the node that needed to change and worked:

XmlDocument xml = new XmlDocument();
xml.Load("\server\configs\teste.exe.config");
xml.SelectNodes("configuration/connectionStrings/add").Item(1).Attributes["connectionString"].Value = "foi";
xml.Save("\server\configs\teste.exe.config");
    
23.03.2017 / 18:41