NHibernate的ACCESS驱动----JetDriver
网上搜NHibernate的驱动都说是JetDriver,但是这个dll被从NHibernate的完整包里面移出了,移到Contrib里面了。需要自己下载整个工程自己编译。
我当时就想省事,找了个把小时有没有现成的JetDriver的dll下载,最后放弃了。自己用SVN导出编译的。当时主要是觉得麻烦,想直接下载一个dll放到项目里就用。现在我提供这个工程的一个打包,大家可以自己下载后编译自己使用的NHibernate对应的版本。
关于JetDriver,配置相关的部分可以看这里 https://www.hibernate.org/361.html#A4 。编译注意事项:为了省空间,libnet下面的3.0我删除了,只留了个2.0,Tools里面的NUnit也删除了。net2.0这下面是NHibernate使用的lib,大家把自己对应的版本COPY进来覆盖,我这里面的是2.1.2版本的。不能使用我的直接编译出NHibernate.JetDriver.dll后换用不同版本的NHibernate文件。
其他注意事项:使用ACCESS 2007的朋友建好2000或者2003的数据库后,可能会发现NHibernate无法使用JOIN,使用INSERT报错。这个不是JetDriver的问题,是ACCESS的设置问题。ACCESS 2007我觉得它是想做成一个傻瓜型的OA软件,出于安全考虑,只让你表格编辑。运行一些高级点的SQL(即使是在ACCESS里面输入SQL语句)都会报错。需要菜单的Access选项中,打开信任中心的设置,在宏设置里面启用所有宏。这样NHibernate就可以完全操作ACCESS的数据库了。
附件列表
NHibernate.JetDriver.zip 添加时间:2009-12-28 12:57:12 下载次数:717Tags:
上一篇:
CCTV的水墨宣传片
相关日志推荐
Lin.x | 2010-01-16 21:45:01
老大....最近在忙什么呢... 加紧更新啊...呵呵 我的域名换了 www.lineks.cn->http://www.leosio.com 麻烦更新下...小叶 | 2010-02-06 01:08:20
哥们,都学linux,也搞c/c++。 能否申请个友情链接么? 名称:鹭鹭设计室 网址:http://blog.luluui.info 描述:鹭鹭设计室-致力于最好的网站设计 贵站链接已加。yhustc | 2010-02-08 16:48:18
不好意思,为了保证质量,本站对友链要求高于等于PR3soros | 2010-02-13 01:31:55
你好!在网上下了你的关于博客搬家的程序,感觉很好。可是我在cmd下总出错,而且最后在相应目录下得不到任何xml文件,怎么办???yhustc | 2010-02-21 11:15:29
网易的模板变了,网易的搬家工具不以用了。百度的不知道变了没有。建议你可以和博客大巴的工具,那个也能导出wordpress使用的XML文件techmango | 2010-03-19 17:25:33
大兄弟,你能不能提供支持NHibernate2.1的JetDriver.DLL啊?yhustc | 2010-03-21 23:54:20
这个是NH2.1.2的shiling | 2010-03-31 10:24:45
我的还是不能用啊。我下载你的包后自己替换了你net2.0下的东西。编译通过输出的NHibernate.JetDriver.Dll,引入到我的其他项目中还是不能用;单步时会出错,提示:Could not find the dialect in the configuration 请问这是什么问题,我始终找不到,按道理应该可以的啊。谢谢shiling | 2010-03-31 10:27:29
另外说明,我采用的是InPlaceConfigurationSource.如下: IDictionary<string, string> properties = new System.Collections.Generic.Dictionary<string, string>(); properties.Add("hibernate.connection.driver_class", "NHibernate.JetDriver.JetDriver, NHibernate.JetDriver"); properties.Add("hibernate.dialect", "NHibernate.JetDriver.JetDialect,NHibernate.JetDriver"); properties.Add("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider"); properties.Add("hibernate.show_sql", "false"); string strConn = GetFullDatabasePath(CORE_DB_PATH); properties.Add("hibernate.connection.connection_string", strConn); InPlaceConfigurationSource source = new InPlaceConfigurationSource(); source.Add(typeof(ActiveRecordBase), properties); ActiveRecordStarter.Initialize(source, new Type[] { typeof(MyClass) }); ----在最后的Initialize这里会出上面的错误 谢谢yhustc | 2010-03-31 19:24:44
把配置项里面的“hibernate.”去掉试试。 The configuration has changed since RC3 and you no longer need to prefix all keys with a hibernate. Things will break if you do. You’ll get a exception stating: Could not find the dialect in the configurationshiling | 2010-04-01 08:54:43
我在官网上找了半天也没找到那个说明。调试通过了,谢谢你yhustc!!!shiling | 2010-04-01 15:36:49
还想请教一个问题,因为我的Nhibernate是从1.0.4.0迁移过来的,在FindAll方法中总是会提示:“指定的初始化字符串不符合ole db规定”,明明前面都已经调试通过了,这里获取数据时为何还是说oledb不符合规定呢。我看了一下我的连接字符串也没有发现错误,我也是c/s的程序,单机运行的。我的代码: ----- public static T[] FindAll() { if (Assembly.GetExecutingAssembly().CreateInstance(typeof(T).FullName) is ISortable) { return ActiveRecordBase<T>.FindAll(new Order[] { new Order("序号", true), new Order("Id", true) }, new SQLCriterion[0]); } return ActiveRecordBase<T>.FindAll(new Order[] { new Order("Id", true) }, new SQLCriterion[0]);//这里出错。 } -- 谢谢你的回复yhustc | 2010-04-02 15:28:29
这个真不清楚,这个错误一般都是连接字符串有问题的时候报的啊。你说调试通过了指的什么?在这个函数之前测试过可以连接上MDB文件进行查询了?shiling | 2010-04-22 16:24:50
yhustc你好,我遇到一个问题:Access中一个表A,有十个字段,其中有一个字段是Id(自动编号),我在用ActiveRecordBase的Save()方法后,再去Access中打开此表,发现数据都存进去了,但是我的代码中再以属性的方式(get,set)获取这个id,仍然是我初始定义的属性值0,也就是说Save()后,没有将这个自动编号的id值,返回给我。请问该如何处理?谢谢。yhustc | 2010-04-22 20:18:10
你可以设置一下show sql,看看执行save的SQL。其实save操作是连续的两条命令,一条insert,一条select取刚才插入的id值。自己执行一下看看能不能正确返回,如果能返回值,按理NHibernate生成的对象id值也能正确赋值的。shiling | 2010-04-23 14:45:55
yhustc你好,我有看执行save的SQL,在C#中,我发现,只有两条语句,一个是NHibernate: insert into Table1(field1,field2) Values(?,?);@p1='XX',@p2='XX' 还有一个是NHibernate: select @@identity. 却没有NHibernate: Select 所有字段 where....查询刚刚插入的数据这条语句,所以导致我的实体类没有得到更新。不知道是这个原因,或者说是不是jetDriver里面少写一些东西呢。期待你的回复,如果可以请留一个邮箱,谢谢。我的邮箱是:shilingstudio@163.comshiling | 2010-04-23 15:11:25
我的实体类中: [PrimaryKey(PrimaryKeyType.Identity, "Id")] public int Id { get { return this._id; } set { this._id = value; } }yhustc | 2010-04-23 19:09:48
Access的select @@identity问题挺典型的。 网上有个评论说的比较详细。 After some research in the Hibernate documentation and on the Internet, I discovered that this is caused by the 'connection release mode'. The default connection release mode seems to release the connection after each SQL statement, so obviously, Access is not able to determine the correct ID of the last inserted record, since the __select @@identity command must be executed on the same connection as its related __insert statement. Now that we know what caused this problem, it is easy to fix it: just make sure that you do not use the default connection release mode when using NHibernate with MS Access. To do so, you should specify the connection release mode in your NHibernate configuration file like this: <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="hibernate.connection.release_mode">on_close</property> </session-factory></hibernate-configuration>shiling | 2010-04-24 10:47:40
yhustc非常感谢你的回复。我的问题得以解决,按照上面的意思,在我的配置代码中添加properties.Add("connection.release_mode","on_close");既可。没想到这个版本的NHibernate会搞出这么多问题,谢谢你的回复。shiling | 2010-04-26 16:48:56
yhustc你好,我将生成的debug文件放在别的机器上测试我的程序,一启动就会出现:”Castle.ActiveRecord.Framework.Internal.EventListener.EventListenerContributor的类型初始值设定项引发异常“ 这个异常提示,在我本机运行时是不出现这个异常的,不知道是不是也是由于哪里没有配置好呢。我在网上找了很久也没有找到相关能解决问题的资料。请问该如何处理?期待你的回复,谢谢。shiling | 2010-04-26 18:19:34
像上面我这样采用硬编码方式进行的配置,如何体现<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">呢shiling | 2010-04-26 18:31:33
因为我一到其他机上测试我的程序,总是会提示Could not complie the mapping document.在网上看到需要在xml中进行配置<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">,但我采用的是硬编码的方式。谢谢yhustc | 2010-04-27 11:22:40
mapping document是hbm.xml文件,应该是这部分有问题。另外,需要在NHibernate的配置里面添加<mapping assembly>这部分,我以前就遇到过没有添加这一部分,无法找到mapping document的问题。