NHibernate.Exceptions.GenericADOException:无法执行查询 [英] NHibernate.Exceptions.GenericADOException : could not execute query

查看:2931
本文介绍了NHibernate.Exceptions.GenericADOException:无法执行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个遗留应用程序(VFP 8),我需要从(不插入)中提取数据。我现在用的是Accnum字段作为主键,在该表中被定义为字符11



出厂配置:

 <?XML版本=1.0编码=UTF-8>?; 
<休眠配置的xmlns =金塔:NHibernate的配置,2.2>
<反射优化器使用=FALSE/>
<会话工厂>
<属性名=connection.provider> NHibernate.Connection.DriverConnectionProvider< /性>
<属性名=方言> NHibernate.Dialect.GenericDialect< /性>
<属性名=connection.driver_class> NHibernate.Driver.OleDbDriver< /性>
<属性名=connection.connection_string>提供商= VFPOLEDB.1;数据源= C:\Analysis\Quantium\development\RD warehouse\_RDAUWH\Data;整理顺序=机器和LT; /性>
<属性名=show_sql>假LT; /性>
< /会话工厂>
< /休眠-结构>

这是我的映射文件:

 <?XML版本=1.0编码=UTF-8>?; 
<休眠映射的xmlns =金塔:NHibernate的映射 - 2.2
装配=RDLabels
命名空间=RDLabels.Domain>

<类名=CustMast>
< ID名称=Accnum栏=Accnum类型=字符串>
<生成器类=分配/>
< / ID>
<属性名=全名/>
<属性名=添加/>
<属性名=国家/>
< /班>
< /休眠映射>



类:

 公共类CustMast 
{
私人字符串_accnum;
公共虚拟字符串Accnum
{
{返回_accnum; }
集合{_accnum =价值; }
}
私人字符串_fullname;
公共虚拟字符串全名
{
{返回_fullname; }
集合{_fullname =价值; }
}
私人字符串_add;
公共虚拟字符串添加
{
{返回_add; }
集合{_add =价值; }
}
私人字符串_state;
公共虚拟字符串国
{
{返回_state; }
集合{_state =价值; }
}
}

下面是获取记录的代码:

 公共CustMast GetByAccnum(字符串accnum)
{$ b $使用b(的ISession会议= NHibernateHelper.OpenSession())
{
CustMast custMast =会话
.CreateCriteria(typeof运算(CustMast))
。新增(Restrictions.Eq(accnum,accnum))
.UniqueResult< CustMast>();
返回custMast;
}
}



完整的错误是:



  NHibernate.Exceptions.GenericADOException:无法执行查询
[选择this_.Accnum为Accnum0_0_,this_.Fullname为Fullname0_0_,this_.Add作为Add0_0_,this_.State作为State0_0_ FROM CustMast THIS_ WHERE this_.Accnum =? ]
名称:CP0 - 价值:00059337444
[SQL:SELECT this_.Accnum为Accnum0_0_,this_.Fullname为Fullname0_0_,this_.Add为Add0_0_,this_.State作为State0_0_ FROM CustMast THIS_ WHERE this_.Accnum =]
---->?; System.IndexOutOfRangeException:无效此OleDbParameterCollection以计数= 0指数0。 - D:\CSharp\NH\NH\\\
hibernate\src\NHibernate\Loader\Loader.cs:1590

运行NHibernate的探查它表明:

 警告:
反射优化性能被忽略了应用程序配置文件。


警告:
System.IndexOutOfRangeException:无效的指数0这个OleDbParameterCollection以计数= 0。
在System.Data.OleDb.OleDbParameterCollection.RangeCheck(的Int32指数)
在System.Data.OleDb.OleDbParameterCollection.GetParameter(的Int32指数)
在System.Data.Common.DbParameterCollection.System .Collections.IList.get_Item在D(的Int32指数)
在NHibernate.Driver.DriverBase.ExpandQueryParameters(IDbCommand的CMD,的SqlString的SqlString):\CSharp\NH\NH\\\
hibernate\src\NHibernate \Driver\DriverBase.cs:行235
在NHibernate.AdoNet.AbstractBatcher.ExpandQueryParameters(IDbCommand的CMD,的SqlString的SqlString)在d:\CSharp\NH\NH\\\
hibernate\src\ NHibernate\AdoNet\AbstractBatcher.cs:在NHibernate.Loader.Loader.PrepareQueryCommand线232
(queryParameters queryParameters,布尔滚动,ISessionImplementor会议)在d:\CSharp\NH\NH\\\
hibernate\\ \\src\NHibernate\Loader\Loader.cs:线1152

错误:此OleDbParameterCollection以计数= 0
无效指数0。


解决方案

我和我的LINQ查询抛出了同样的错误挣扎每当我照过的参数。如果我不传递任何参数,并做了session.Query(),他们将很好地工作。



我这个奋斗了几天,但我发现这个NHibernate的JIRA票< A HREF =https://nhibernate.jira.com/browse/NH-2893相对=nofollow>此处。它解释了SQLParameters和i系列DB2提供一个明显的问题。



我知道你正在使用不同的供应商,但你可能会从刚刚下载最新的NHibernate的核心源代码中获益,构建它,并引用项目中的最新版本。它固定我的问题。


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.

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>

The class:

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 record:

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

The full error is:

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

Running NHibernate Profiler it 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.

解决方案

I was struggling with my linq queries throwing the same error whenever i passed them a parameter. If i didn't pass any parameters and did a session.Query() they would work fine.

I struggled with this for days but i found this Nhibernate jira ticket here . It explains an apparent problem with SQLParameters and the Iseries Db2 provider.

I understand you're using a different provider but you might benefit from just downloading the latest Nhibernate core source code, building it, and referencing the latest version in your project. It fixed my issue.

这篇关于NHibernate.Exceptions.GenericADOException:无法执行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆