• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C# - Working with config files and connection strings

mlm

Senior member
I'm trying to change up how the application I'm working on currently gets its database settings. Right now, all the settings are saved in a plain text file. So I'm trying to get it to work with a config file, but the following code, which I copied and pasted directly from the Visual Studio documenation, refuses to compile.

--

using System;
using System.Configuration;

class Program
{
static void Main()
{
ConnectionStringSettings settings;
settings = ConfigurationManager.ConnectionStrings["DatabaseConnection"];
if (settings != null)
{
Console.WriteLine(settings.ConnectionString);
}
}
}

--

It can't find ConnectionStringSettings which is supposed to be in System.Configuration. Anybody know what's going on?

What's the best way to store sensitve modifiable settings anyway? The documentation gives a walkthrough for encrypting ASP.NET config files, would I be able to do the same thing with application config files?
 
That is .net 2.0 code (ConfigurationManager.ConnectionStrings). You will need to include a reference to System.Configuration.dll
 
Originally posted by: mlm
How would I do that? I've never worked with dll files before.

Where you see your code files, forms etc on your right in the solution explorer window, you will see a folder called references. Right click on it and select add reference. Under the .net tab you can select the system.configuration dll

 
You don't always have the References folder. If you don't, just right-click on your project name and you'll have an "Add Reference" option. Once you do that, just go into the first tab in the popup and find System.Configuration.

-Jax
 
Back
Top