title: OleDbCommand.ExecuteReader Throwing Exception
body: <p>My C# .NET 3.5 application is throwing an unusual exception when executing <code>OleDbCommand.ExecuteReader</code>.  The application makes 5 similar queries of an Access 2007 database.  Three of the queries execute without any problems; the other 2 cause exactly the same exception to be thrown.</p>
  
  <p>This is a query that passes:</p>
  
  <pre><code>String query =
      "SELECT " +
          "bas.[BAS BACnet Object Type/Instance], " + // OBJECT_IDENTIFIER_ATTRIBUTE/ITEM_REFERENCE_ATTRIBUTE
          "bas.[BAS BACnet Object Name], " +          // USER_NAME_ATTRIBUTE
          "bas.[BAS Point List Description], " +      // DESCRIPTION_ATTRIBUTE
          "bas.[BAS Monitor Only], " +                // MONITOR_ONLY_ATTRIBUTE
          "ref.[ENUM_H], " +                          // PROPERTY_REFERENCE_VALUE_ATTRIBUTE
          "yk.[CCC Max Value (eng units)], " +        // MAX_PRESENT_VALUE_ATTRIBUTE
          "yk.[CCC Min Value (eng units)], " +        // MIN_PRESENT_VALUE_ATTRIBUTE
          "yk.[CCC Enum/Data Set], " +                // UNITS_ATTRIBUTE
          "ore.[ORE COV Increment], " +               // COV_INCREMENT_ATTRIBUTE
          "ore.[ORE Display Precision] " +            // DISPLAY_PRECISION_ATTRIBUTE
      "FROM (([OV2 BAS] AS bas " +
      "INNER JOIN [OV2 ORE] AS ore ON bas.[Ref ID] = ore.[Ref ID]) " +
      "INNER JOIN [OV2 RefID] AS ref ON bas.[Ref ID] = ref.[Ref ID]) " +
      "INNER JOIN [YK CAPP] AS yk ON bas.[Ref ID] = yk.[Ref ID] " +
      "WHERE bas.[BAS BACnet Object Type/Instance] LIKE 'AV%';";
  
  this.RunQuery(query, MappingTable.AV_QUERY_IP_FIELDS, this.IPAnalogValuesList);
  </code></pre>
  
  <p>This is a query that throws throws an exception:</p>
  
  <pre><code>String query =
      "SELECT " +
          "bas.[BAS BACnet Object Type/Instance], " + // OBJECT_IDENTIFIER_ATTRIBUTE/ITEM_REFERENCE_ATTRIBUTE
          "bas.[BAS BACnet Object Name], " +          // USER_NAME_ATTRIBUTE
          "bas.[BAS Point List Description], " +      // DESCRIPTION_ATTRIBUTE
          "bas.[BAS Monitor Only], " +                // MONITOR_ONLY_ATTRIBUTE
          "ref.[ENUM_H], " +                          // PROPERTY_REFERENCE_VALUE_ATTRIBUTE
          "ses.[ENUM_H], " +                          // STATES_TEXT_ATTRIBUTE
          "ore.[ORE States] " +                       // ACTIVE_TEXT_ATTRIBUTE/INACTIVE_TEXT_ATTRIBUTE
      "FROM (([OV2 BAS] AS bas " +
      "INNER JOIN [OV2 RefID] AS ref ON bas.[Ref ID] = ref.[Ref ID]) " +
      "INNER JOIN [OV2 ORE] AS ore ON bas.[Ref ID] = ore.[Ref ID]) " +
      "INNER JOIN [StatesEnumSet] AS ses ON ore.[ORE States] = ses.[ID] " +
      "WHERE bas.[BAS BACnet Object Type/Instance] LIKE 'BV%';";
  
  this.RunQuery(query, MappingTable.BV_QUERY_FIELDS, this.BinaryValuesList);
  </code></pre>
  
  <p>Here is how all of the queries are executed:</p>
  
  <pre><code>private void RunQuery(String query, Int32 fieldCount, Object target)
  {
      OleDbCommand cmd = null;
      OleDbDataReader reader = null;
  
      try
      {
          OleDbConnectionStringBuilder connection = new OleDbConnectionStringBuilder();
          connection.Provider = "Microsoft.ACE.OLEDB.12.0";
          connection.DataSource = XML_Generator.Program.MappingTableFilename;
          connection.PersistSecurityInfo = false;
  
          this.DbConnection = new OleDbConnection(connection.ToString());
          this.DbConnection.Open();
  
          using (cmd = new OleDbCommand(query, this.DbConnection))
          {
              cmd.Connection = this.DbConnection;
              cmd.CommandText = query;
              cmd.CommandType = System.Data.CommandType.Text;
              reader = cmd.ExecuteReader(); // &lt;== Exception is thrown here.
  
              while (reader.Read())
              {
                  . . .
              }
          }
  
          if (this.DbConnection != null)
          {
              this.DbConnection.Close();
              this.DbConnection = null;
          }
      }
      catch (Exception e)
      {
          Console.WriteLine(e.ToString());
      }
  }
  </code></pre>
  
  <p>This is the exception:</p>
  
  <blockquote>
    <p>System.Data.OleDb.OleDbException: No value given for one or more required parame
    ters.
       at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResul
    t hr)
       at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARA
    MS dbParams, Object&amp; executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&amp; executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Ob
    ject&amp; executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behav
    ior, String method)
       at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.OleDb.OleDbCommand.ExecuteReader()
       at XML_Generator.MappingTable.RunQuery(String query, Int32 fieldCount, Object
     target) in C:\ccmdb\prep\ov2_shared_cec_v1.0\ov2_shared_cec\Private\Tools\XML_G
    enerator\XML_Generator\MappingTable.cs:line 312</p>
  </blockquote>
  
  <p>Any help is appreciated.  Thanks.</p>