将 Foxpro 表与 nHibernate 一起使用

发布于 2024-12-24 22:21:43 字数 2827 浏览 0 评论 0原文

根据这篇文章 NHibernate 配置连接到 Visual FoxPro 8.0?< /a> 可以将 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).

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谢绝鈎搭 2024-12-31 22:21:43

我首先要确保我有最新的 VFP OleDb 提供程序...
另一个答案也有一个链接。 此外,连接字符串将与您的 {Microsoft Visual FoxPro Driver} 略有不同,以反映新的连接字符串。

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.

娜些时光,永不杰束 2024-12-31 22:21:43

这对我有用:

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

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 + "]");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文