2012-01-06 37 views
1

根据这篇文章NHibernate configuration to connect to Visual FoxPro 8.0?可以将nHibernate连接到Foxpro。在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). 
+0

的第一个错误看起来像一个映射错误,也许列映射两次 – Firo 2012-01-06 15:08:51

+0

这很可能是一个映射错误。我已经打开了另一个与连接字符串更相关的问题。 http://stackoverflow.com/questions/8774702/nhibernate-exceptions-genericadoexception-could-not-execute-query – 2012-01-10 10:36:08

+0

from子句应该是表的完整路径(在你的第一个例子中) – 2012-03-28 12:01:13

回答

0

我首先要确保我有最新的VFP OLEDB提供... another answer has a link too.此外,连接字符串将是你有什么{微软Visual FoxPro驱动程序},以反映新的略有不同。

+0

OleDB驱动程序是最新的,并且我通过Foxpro使用连接字符串以及通过.Net使用OleDbConnection来测试连接 – 2012-01-10 10:32:49

0

这个工作对我来说:

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 + "]"); 
    } 
}