将 Foxpro 表与 nHibernate 一起使用
根据这篇文章 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我首先要确保我有最新的 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.
这对我有用:
以及映射类:
This works for me:
And the mapping class: