NHibernate.Exceptions.GenericADOException: request failed

I have an outdated application (vfp 8) in which I need to extract data from (without inserts). I use the Accnum field as the primary key, it is defined in the table as symbol 11.

Factory Configuration:

<?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <reflection-optimizer use="false" /> <session-factory> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect">NHibernate.Dialect.GenericDialect</property> <property name="connection.driver_class">NHibernate.Driver.OleDbDriver</property> <property name="connection.connection_string">Provider=VFPOLEDB.1;Data Source=C:\Analysis\Quantium\development\RD warehouse\_RDAUWH\Data;Collating Sequence=MACHINE</property> <property name="show_sql">false</property> </session-factory> </hibernate-configuration> 

This is my mapping file:

 <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="RDLabels" namespace="RDLabels.Domain"> <class name="CustMast"> <id name="Accnum" column="Accnum" type="string"> <generator class="assigned"/> </id> <property name="Fullname" /> <property name="Add" /> <property name="State" /> </class> </hibernate-mapping> 

Grade:

 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; } } } 

Here is the code that gets the entry:

 public CustMast GetByAccnum(String accnum) { using (ISession session = NHibernateHelper.OpenSession()) { CustMast custMast = session .CreateCriteria(typeof(CustMast)) .Add(Restrictions.Eq("Accnum", accnum)) .UniqueResult<CustMast>(); return custMast; } } 

Full error:

 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 = ?] ----> System.IndexOutOfRangeException : Invalid index 0 for this OleDbParameterCollection with Count=0. - d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:1590 

The launch of NHibernate Profiler shows:

 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. 
+4
source share
2 answers

I struggled with my linq queries throwing the same error when I passed the parameter to them. If I did not pass any parameters and did session.Query (), they will work fine.

I struggled with this for several days, but I found this Nhibernate jira ticket here . This explains the obvious problem with SQLParameters and the Iseries Db2 provider.

I understand that you are using a different provider, but it may be useful for you to simply download the latest Nhibernate kernel source code, create it and link to the latest version of your project. He fixed my problem.

+2
source

First of all, I will try to run this in SQL and see what happens, as it may be a data problem.

CHOOSE 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 = '00059337444'

Is the Accnum column defined as a string type (varchar, nvarchar, etc.) in your database?

Change OK, the next step is to actually confirm the SQL submission to FoxPro. You will need to configure logging (or download a trial copy of NHProf ) to find out if SQL is correct. Your setup and code look right, but I'm not 100% sure of the dialect choice, as this can cause problems.

As I understand it, you saw this and this .

Edit2 NHProf error seems to me that it considers that your Id should be Int32, since it looks like it is calling at System.Data.OleDb.OleDbParameterCollection.GetParameter(Int32 index) .

I think you need to add this to your comparisons: -

 <id name="Accnum" column="Accnum" type="string" > 

Note the extra type="string"

0
source

Source: https://habr.com/ru/post/1389855/


All Articles