根据这篇文章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).
答案 0 :(得分:0)
我首先要确保我拥有最新的VFP OleDb提供商...... another answer has a link too.此外,连接字符串与{Microsoft Visual FoxPro Driver}的连接字符串略有不同,以反映新的连接字符串。
答案 1 :(得分: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 + "]");
}
}