Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Retrieving connection string from app.config

Retrieving connection string from app.config

Scheduled Pinned Locked Moved C#
tutorialcsharp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IMC2006
    wrote on last edited by
    #1

    I am building a C# window app and am trying to 1. Create a DataAccess class which retrievs the connection string from app.config and then 2. call the DataAccess from a form load. I have successfully created the DataAccess.cs class but am having difficulties creating the retrieval of the app.config connection string. Does anyone have suggestions or a GOOD site with a simple C# example of how to do this.

    C 1 Reply Last reply
    0
    • I IMC2006

      I am building a C# window app and am trying to 1. Create a DataAccess class which retrievs the connection string from app.config and then 2. call the DataAccess from a form load. I have successfully created the DataAccess.cs class but am having difficulties creating the retrieval of the app.config connection string. Does anyone have suggestions or a GOOD site with a simple C# example of how to do this.

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      At the top of your file put: using System.Configuration; When you want to retrieve the setting use:

      string connString = ConfigurationSettings.AppSettings["MyConnectionStringSetting"];

      (Change "MyConnectionStringSetting" to the name of the setting in the app.config[^] file)


      "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups