This is my app.config

<?xml version="1.0" encoding="utf-8" ?>
    <add key="radicalGuard"
         value="Data Source = MICHAEL-PC\SQLEXPRESS; Initial Catalog = radicalGuardDB; Integrated Security = True" />

And this is my connection string

SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["radicalGuard"].ToString());

Whenever I try to debug, it says "object reference not set to an instance of an object", and if I try to run without debugging it will say "application has stopped working"..

Need help.

You are using an obsolete deprecated method to retrieve the application settings.
I would prefer to use

SqlConnection con = new SqlConnection(System.Properties.Settings.Default.radicalGuard);

Hope this helps


What's the difference other than its deprecated?

Edited 5 Years Ago by AngelicOne: n/a

The difference, in the tests i did, is that the ConfigurationSettings.AppSettings is always returning an empty array (??), so it is currently compiling without error, but not working to me (VS2010 .NET 4.0).

Hope this helps.

I'm trying to change my config file to work with the new method of using it. I got an error saying appSettings has invalid child element settings.

<?xml version="1.0" encoding="utf-8" ?>
    <setting name="radicalGuard">
        Data Source=.\SQLEXPRESS;Initial Catalog=radicalGuardDB;Integrated Security=True

Where would I put the appsettings? Or am I missing something?

This question has already been answered. Start a new discussion instead.