使用 Access 数据库的组件在官方下载的 NHibernate-contrib 文件里,有个 NHibernate.JetDriver.dll,这个文件也是必须的。其实,在app.config文件里加入NHibernate属性的语句是:

NHibernate 搭载 Access 数据库<? xml version="1.0" encoding="utf-8"  ?>
NHibernate 搭载 Access 数据库
< configuration >
NHibernate 搭载 Access 数据库  
< configSections >
NHibernate 搭载 Access 数据库    
< section  name ="nhibernate"  type ="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
NHibernate 搭载 Access 数据库  
</ configSections >
NHibernate 搭载 Access 数据库  
< nhibernate >
NHibernate 搭载 Access 数据库    
< add  key ="hibernate.connection.provider"  value ="NHibernate.Connection.DriverConnectionProvider" />
NHibernate 搭载 Access 数据库    
< add  key ="hibernate.dialect"  value ="NHibernate.JetDriver.JetDialect, NHibernate.JetDriver" />
NHibernate 搭载 Access 数据库    
< add  key ="hibernate.connection.driver_class"  value ="NHibernate.JetDriver.JetDriver, NHibernate.JetDriver" />
NHibernate 搭载 Access 数据库    
< add  key ="hibernate.connection.connection_string"  value ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hibtest.mdb" />
NHibernate 搭载 Access 数据库  
</ nhibernate >
NHibernate 搭载 Access 数据库
</ configuration >

那个 dialect 和 driver_class 的值里面前面是类名称,后面是命名空间名称,中间用逗号分开,不可缺少。

默认配置的注意事项:

1. Access 数据表中类型为日期时间的字段,在类中所对应的类型不能为 DateTime,而要改为 string。原因是插入时没有加引号。

2. 对于名为 User、Username 和 Password 的字段,将会引起插入错误,原因是与字段名与关键字冲突,解决方法是用中括号把字段名括起来。

3. 作为外部调用 DLL,执行时效率会比较差。解决方法是把 JetDriver 也编译进主模块。

相关文章:

  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2022-01-02
  • 2022-12-23
  • 2021-07-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-28
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2021-10-21
相关资源
相似解决方案