【问题标题】:Using Foxpro tables with nHibernate将 Foxpro 表与 nHibernate 一起使用
【发布时间】:2012-01-06 04:49:04
【问题描述】:

根据这篇帖子NHibernate configuration to connect to Visual FoxPro 8.0? 可以将 nHibernate 连接到 Foxpro。

当我尝试这种配置 (OLEDB) 时:

<?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;Data Source="C:\Analysis\Quantium\development\RD warehouse\_RDAUWH\Data";Collating Sequence=general</property>
<property name="show_sql">false</property>

我得到了错误

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

当我尝试这种配置时(ODBC):

<?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.OdbcDriver</property>
<property name="connection.connection_string">Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB="myDirectory";Exclusive=No;Collate=Machine;NULL=NO;DELETED=YES;BACKGROUNDFETCH=NO;</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>

我得到了错误

System.Data.Odbc.OdbcException : ERROR [S1000] [Microsoft][ODBC Visual FoxPro Driver]Fox Error 1
ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed
ERROR [01000] [Microsoft][ODBC Driver Manager] The driver doesn't support the version of ODBC behavior that the application requested (see SQLSetEnvAttr).

【问题讨论】:

  • 第一个错误看起来像是映射错误,可能列映射了两次
  • 很可能是映射错误。我打开了另一个与映射比连接字符串更相关的问题。 stackoverflow.com/questions/8774702/…
  • from 子句应该是表的完整路径(在您的第一个示例中)

标签: nhibernate visual-foxpro


【解决方案1】:

我首先要确保我拥有最新的 VFP OleDb 提供程序... another answer has a link too. 此外,连接字符串会与您的 {Microsoft Visual FoxPro Driver} 略有不同,以反映新的。

【讨论】:

  • OleDB 驱动程序是最新的,我已经通过 Foxpro 使用连接字符串以及通过 .Net 使用 OleDbConnection 测试了连接
【解决方案2】:

这对我有用:

var connectionString = @"Provider=VFPOLEDB.1;Data Source={0};SourceType=DBF".FormatWith(directory);
var cfg = new Configuration()
    .DataBaseIntegration(c =>
    {
        c.Dialect<GenericDialect>();
        c.ConnectionString = connectionString;
        c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
        c.BatchSize = 100;
        c.Driver<OleDbDriver>();
    });

还有映射类:

public class MyClassMap : ClassMapping<<MyClass>
{
    public MyClassMap (string filename)
    {
        Table("[" + filename + "]");
    }
}

【讨论】:

    猜你喜欢
    • 2023-03-23
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多