1

According to this post NHibernate configuration to connect to Visual FoxPro 8.0? it is possible to connect nHibernate to Foxpro.

When I try this configuration (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>

I get the error

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

When I try this configuration (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>

I get the error

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).
Community
  • 1
  • 1
CarbonMan
  • 4,350
  • 12
  • 54
  • 75
  • the first error looks like a mapping error, maybe column mapped twice – Firo Jan 06 '12 at 15:08
  • It may well be a mapping error. I have opened another question that would be more related to the mapping than the connection string. http://stackoverflow.com/questions/8774702/nhibernate-exceptions-genericadoexception-could-not-execute-query – CarbonMan Jan 10 '12 at 10:36
  • The from clause should be the full path to the table (in your first example) – Robert Wagner Mar 28 '12 at 12:01

2 Answers2

0

I would first make sure I had the lastest VFP OleDb provider... another answer has a link too. In addition, the connection string will be slightly different from what you have of {Microsoft Visual FoxPro Driver} to reflect the new one.

Community
  • 1
  • 1
DRapp
  • 47,638
  • 12
  • 72
  • 142
  • The OleDB driver is the latest, and I have tested the connection using the connection string through Foxpro as well as OleDbConnection through .Net – CarbonMan Jan 10 '12 at 10:32
0

This works for me:

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

And the mapping class:

public class MyClassMap : ClassMapping<<MyClass>
{
    public MyClassMap (string filename)
    {
        Table("[" + filename + "]");
    }
}
Robert Wagner
  • 17,515
  • 9
  • 56
  • 72