c# – NHibernate.Exceptions.GenericADOException:无法执行查询

c# – NHibernate.Exceptions.GenericADOException:无法执行查询,第1张

概述我有一个遗留应用程序(vfp 8),我需要从中提取数据(无插入).我使用Accnum字段作为主键,它在表中定义为字符11. 工厂配置: <?xml version="1.0" encoding="utf-8" ?><hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"><reflection-optimizer use 我有一个遗留应用程序(vfp 8),我需要从中提取数据(无插入).我使用Accnum字段作为主键,它在表中定义为字符11.

工厂配置:

<?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>

这是我的映射文件:

<?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 />    </ID>    <property name="Fullname" />    <property name="Add" />    <property name="State" />  </class>  </hibernate-mapPing>

班级:

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

以下是获取记录的代码:

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

完整的错误是:

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_.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

运行NHibernate Profiler,它显示:

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 235at NHibernate.AdoNet.AbstractBatcher.ExpandqueryParameters(IDbCommand cmd,sqlString sqlString) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\AdoNet\AbstractBatcher.cs:line 232at NHibernate.Loader.Loader.PreparequeryCommand(queryParameters queryParameters,Boolean scroll,ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:line 1152ERROR: InvalID index 0 for this oleDbParameterCollection with Count=0.
解决方法 每当我传递一个参数时,我都在努力解决我的linq查询丢失相同的错误.如果我没有传递任何参数并做了session.query()他们会工作正常.

我挣扎了几天,但我发现这张Nhibernate jira票here.它解释了sqlParameters和IserIEs Db2提供程序的明显问题.

我知道您使用的是其他提供商,但您可能只需下载最新的Nhibernate核心源代码,构建它并在项目中引用最新版本即可获益.它解决了我的问题.

总结

以上是内存溢出为你收集整理的c# – NHibernate.Exceptions.GenericADOException:无法执行查询全部内容,希望文章能够帮你解决c# – NHibernate.Exceptions.GenericADOException:无法执行查询所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1234293.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存