Accessing connection string created by C#

During the "Addition of new datasource", a connection string is created and stored.

A variable name is assigned to the string. In my case TMIConnectionString.

Where is this stored and how does one access and use it

Thanks,

Lance



Answer this question

Accessing connection string created by C#

  • cr4sh3d.r00t

    Take a look in your app.config file for it. As for how you use it, because you used the wizard to setup the data source it should be used automatically.

  • cobra99sc

    Hey Lance,

    You also need to add System.Configuration as a reference in your application.

    Right-click on "References" in the solutions panel, click on "Add Reference...", and then choose System.Configuration from the .NET tab.

    Regards,

    Dave



  • Arulvel

    Thanks for the responses.

    I added the code to my test app.  An error arises.

    The name 'ConfigurationManager' does not exist in the current context.

    I added 'using System.Configuration' to the app.  This did not help.

    I read that the class is new to the 2.0 .Net framework.  I am running that framework due to its installation by me prior to the install of VC# Express. 

    Also, I verified the version using System.Environment.Version.ToString(); method.  The result was:2.0.50727.42.

    Am I possibly overlooking something simple here

    Thanks again,

    Lance

     


  • JWBrouillette

    In the "Add New DataSource..." wizard it asks you if you want to save it to the configuration file.

    If you say yes, it saves it in the app.config for a winform application within <connectionStrings>...</connectionStrings>.

    To access it in code,

    string connectionString = ConfigurationManager.ConnectionStrings["TMIConnectionString"].ConnectionString;

    Regards,

    Dave



  • Accessing connection string created by C#