locked
how to access the connection string RRS feed

  • Question

  • how do i access this connectoinstring from my app. i have a app.config defined as follows
    1 <?xml version="1.0" encoding="utf-8" ?> 
    2 <configuration> 
    3     <configSections> 
    4     </configSections> 
    5     <connectionStrings> 
    6         <add name="ConsoleApplication1.Properties.Settings.db_TestConnectionString" 
    7             connectionString="server=localhost;user id=root;Password=secret;persist security info=True;database=db_Test" 
    8             providerName="MySql.Data.MySqlClient" /> 
    9     </connectionStrings> 
    10 </configuration> 
     
    Saturday, November 29, 2008 1:18 PM

Answers

  • looks like you set it through settings, so go this way

    string conn=Properties.Settings.Default.db_TestConnectionString;



    if not, go this way

    at the top
    using System.Configuration;   (add reference to System.Configuration  as well)

    and this way


    string conn= ConfigurationManager.ConnectionStrings["ConsoleApplication1.Properties.Settings.db_TestConnectionString"].ConnectionString



     




    Arjun Paudel Not Getting Live Alerts at the moment
    Saturday, November 29, 2008 1:35 PM