How to check incoming bool and set private field to then be sent to Base Constructor
<p>I am not sure how to do this.  </p>

<p><strong>The goal:</strong> I want to check the incoming bool useWebServiceConnection (as you see below) and set the private field connectionString before passing it to the base constructor based on useWebServiceConnection to set the connectionString.</p>

<p>I think the base class constructor is called first always right?  So this is not going to work.</p>

<p>Right now I also get "Cannot Access Static Property in Static Context" for this line:</p>

<pre><code>public ProjectDB(bool useWebServiceConnection) : base(connectionString)
</code></pre>

<p><strong>BASE CLASS:</strong></p>

<p>public class DatabaseBase
 {
  private readonly string connectionString;
  private bool useCounters;</p>

<p>public DatabaseBase(string connectionString)
  {
   this.connectionString = connectionString;
  }</p>

<p><strong>DERIVED CLASS:</strong></p>

<pre><code>public class ProjectDB : DatabaseBase
{
    private bool useWebServiceConnection;
    private string connectionString;

private bool isWebServiceCall;

public ProjectDB(bool useWebServiceConnection) : base(connectionString)
{
    this.useWebServiceConnection = useWebServiceConnection;
    connectionString = this.useWebServiceConnection == true ? ConfigurationManager.AppSettings["ServiceConnectionString"] : ConfigurationManager.AppSettings["SomeOtherConnectionString"];
}

private SqlConnection CreateConnection()
{
    return new SqlConnection(ConnectionString);
}
</code></pre>

<p><strong>The Derived class originally worked like this before I changed what you see above (we have had it working like this until the need to check a bool and change connection strings whenever needed):</strong></p>

<pre><code>public class ProjectDB : DatabaseBase
{

    readonly static string connectionString = ConfigurationManager.AppSettings["SomeOtherConnectionString"];

    public ProjectDB() : base(connectionString)
    {
    }

    private SqlConnection CreateConnection()
    {
        return new SqlConnection(connectionString);
    }
</code></pre>

<p><strong>UPDATED:</strong>  Here's what I came up with.  Look at the original vs. what I tried vs. what I came up with based off your help:</p>

<pre><code>public class ProjectDB : DatabaseBase
 {
    readonly static string connectionString = ConfigurationManager.AppSettings["SomeOtherConnectionString"];

    private bool useWebServiceConnection;

     private bool isWebServiceCall;

    public ProjectDB() : base(connectionString)
    {
    }

    public ProjectDB(bool useWebServiceConnection) : base(useWebServiceConnection
            ? ConfigurationManager.AppSettings["ServiceConnectionString"]
            : ConfigurationManager.AppSettings["SomeOtherConnectionString"])
    {

    }
</code></pre>

<p>Notice that I have a local connectionString field in the derived class.  That's so existing code can just call and instantiate ProjectDB() without passing in any value and that means it will just use the default DB conneciton string "SomeOtherConnection" as it's initialized ast the top of the derived class as you can see.</p>

<p>We also have the 2nd overloaded constructor now.  With your help, now I have the option of specifying whether to use a special service connection string when I create a new ProjectDB object.</p>

<p>I think this is a good solution.  If not, or if you have an even better cleaner impelementation in mind let me know but I learned some good ideas and didn't know I could sort of forward that local constructor's param to the base constructor like this so thanks a lot...now I know.</p>

<p>One thing though, I don't really need a local backing field useWebServiceConnection now that I've just passed it through to my base class's constructor.  So this comes obsolete so I removed it from the constructor:</p>

<pre><code>this.useWebServiceConnection = useWebServiceConnection;
</code></pre>
