views:

45

answers:

1

I am hoping someone can help point me in the right direction. I was having a StackOverFlow error with my Settings.Designer.cs file. I manually regenerated the file according to this post HERE Now my Designer file looks like it is supposed to, so they tell me, but everywhere in my Class Library(30 places) that was accessing the Settings File now throws a Object reference is required error

Is this obvious to everyone else? What am I doing wrong or what do I need to do to fix this? Below are what my Settings.Designer.cs file and an example of the class library, respectively, look like.

 public string CMOSQLConn {
        get {
            return ((string)(this["CMOSQLConn"]));
        }
    }


 public class SupportWorker
{
    public DataSet RetrieveSupportWorkers()
    {
        DataSet ds = new DataSet("table");
        SqlConnection cnn = new SqlConnection(Settings.CMOSQLConn);
        SqlCommand cmd = new SqlCommand("spSelectSupportWorkers", cnn) {CommandType = CommandType.StoredProcedure};
        SqlDataAdapter da = new SqlDataAdapter(cmd);

EDIT 1

I am going to post this in hopes that if it is glaringly wrong and just seems to be correct that someone will point it out.

I replaced all instances of --> SqlConnection cnn = new SqlConnection(Settings.CMOSQLConn); with the following -->SqlConnection cnn = new SqlConnection(Settings.Default.CMOSQLConn);

I have no idea why that makes it work but....

+1  A: 

All of the properties in the settings class are instance properties. In order to use them, you need an instance of the Settings class. The standard way to do this is to access the static Default property on the Settings class, which returns an instance of Settings. From there you can access the individual properties.

If it was working before without using Default...something was seriously wrong.

Thank You for taking the time to explain it. I'm grateful.
Refracted Paladin