title: NHibernate.Exceptions.GenericADOException : could not execute query
body: <p>I have a legacy application (vfp 8) that I need to pull data from (no inserts). I am using the Accnum field as the primary key, it is defined in the table as character 11.</p>
  
  <p>Factory configuration:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"&gt;
  &lt;reflection-optimizer use="false" /&gt;
  &lt;session-factory&gt;
  &lt;property name="connection.provider"&gt;NHibernate.Connection.DriverConnectionProvider&lt;/property&gt;
  &lt;property name="dialect"&gt;NHibernate.Dialect.GenericDialect&lt;/property&gt;
  &lt;property name="connection.driver_class"&gt;NHibernate.Driver.OleDbDriver&lt;/property&gt;
  &lt;property name="connection.connection_string"&gt;Provider=VFPOLEDB.1;Data Source=C:\Analysis\Quantium\development\RD warehouse\_RDAUWH\Data;Collating Sequence=MACHINE&lt;/property&gt;
  &lt;property name="show_sql"&gt;false&lt;/property&gt;
  &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>This is my mapping file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                 assembly="RDLabels"
                 namespace="RDLabels.Domain"&gt;
  
    &lt;class name="CustMast"&gt;
      &lt;id name="Accnum" column="Accnum" type="string"&gt;
      &lt;generator class="assigned"/&gt;
      &lt;/id&gt;
      &lt;property name="Fullname" /&gt;
      &lt;property name="Add" /&gt;
      &lt;property name="State" /&gt;
    &lt;/class&gt;  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>The class:</p>
  
  <pre><code>public class CustMast
  {
      private string _accnum;
      public virtual string Accnum
      {
          get { return _accnum; }
          set { _accnum = value; }
      }
      private string _fullname;
      public virtual string Fullname
      {
          get { return _fullname; }
          set { _fullname = value; }
      }
      private string _add;
      public virtual string Add
      {
          get { return _add; }
          set { _add = value; }
      }
      private string _state;
      public virtual string State
      {
          get { return _state; }
          set { _state = value; }
      }
  }
  </code></pre>
  
  <p>Here is the code that gets the record:</p>
  
  <pre><code>public CustMast GetByAccnum(String accnum)
  {
          using (ISession session = NHibernateHelper.OpenSession())
          {
              CustMast custMast = session
                                  .CreateCriteria(typeof(CustMast))
                                  .Add(Restrictions.Eq("Accnum", accnum))
                                  .UniqueResult&lt;CustMast&gt;();
              return custMast;
          }
  }
  </code></pre>
  
  <p>The full error is:</p>
  
  <pre><code>NHibernate.Exceptions.GenericADOException : could not execute query
  [ SELECT this_.Accnum as Accnum0_0_, this_.Fullname as Fullname0_0_, this_.Add as Add0_0_, this_.State as State0_0_ FROM CustMast this_ WHERE this_.Accnum = ? ]
  Name:cp0 - Value:00059337444
  [SQL: SELECT this_.Accnum as Accnum0_0_, this_.Fullname as Fullname0_0_, this_.Add as Add0_0_, this_.State as State0_0_ FROM CustMast this_ WHERE this_.Accnum = ?]
  ----&gt; System.IndexOutOfRangeException : Invalid index 0 for this OleDbParameterCollection with Count=0. - d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:1590
  </code></pre>
  
  <p>Running NHibernate Profiler it shows:</p>
  
  <pre><code>WARN: 
  reflection-optimizer property is ignored out of application configuration file.
  
  
  WARN: 
  System.IndexOutOfRangeException: Invalid index 0 for this OleDbParameterCollection with Count=0.
  at System.Data.OleDb.OleDbParameterCollection.RangeCheck(Int32 index)
  at System.Data.OleDb.OleDbParameterCollection.GetParameter(Int32 index)
  at System.Data.Common.DbParameterCollection.System.Collections.IList.get_Item(Int32 index)
  at NHibernate.Driver.DriverBase.ExpandQueryParameters(IDbCommand cmd, SqlString sqlString) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Driver\DriverBase.cs:line 235
  at NHibernate.AdoNet.AbstractBatcher.ExpandQueryParameters(IDbCommand cmd, SqlString sqlString) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\AdoNet\AbstractBatcher.cs:line 232
  at NHibernate.Loader.Loader.PrepareQueryCommand(QueryParameters queryParameters, Boolean scroll, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:line 1152
  
  ERROR: 
  Invalid index 0 for this OleDbParameterCollection with Count=0.
  </code></pre>