问题使用ODP与NHibernate问题、ODP、NHibernate

2023-09-06 23:52:26 作者:骄傲 ゛旳 王〆

我有.net 3.5应用程序写在C#中使用NHibernate。 之前我有OracleClientDriver在connection.driver_class财产,那说我用System.Data.Oracle和一切工作正常,但由于某些原因,现在我需要使用消耗臭氧潜能值,所以这个属性更改为:NHibernate.Driver.OracleDataClientDriver 当我运行我的code,我得到以下会话工厂创建过程中的错误:

I have .NET 3.5 application wrote in C# using NHibernate. Before I has OracleClientDriver in connection.driver_class property, that say that I use System.Data.Oracle and all works fine, but for some reasons now I need using ODP, so I changed this property to: NHibernate.Driver.OracleDataClientDriver. When I run my code I get following error during Session Factory creation:

Unable to cast object of type 'Oracle.DataAccess.Client.OracleConnection' to type 'System.Data.Common.DbConnection'

在短暂的搜索在Inernet我找到解决方案:加一句:

After short searching in Inernet I found solution: to add:

<property name="hbm2ddl.keywords">none</property>

所以,现在NHibernate的成功建立会话工厂,但下降session.Flush()具有以下错误:

So now NHibernate successfully build Session Factory but fall in session.Flush() with following error:

System.ArgumentException: Value does not fall within the expected range
at Oracle.DataAccess.Client.OracleParameter.set_DbType(DbType value)
at NHibernate.Driver.DriverBase.InitializeParameter(IDbDataParameter dbParam, String name, SqlTypes sqlType)

任何想法? 谢谢你的未来。 但是,这给我下面的

Any ideas? Thank you for ahead. But this give me following

推荐答案

我得到它的工作!

我赢了! 所以我以前一样: 我得到Oracle.DataAccess.dll从Oracle客户端bin目录,从我的项目汇编中引用它。当我运行NHibernate的配置()函数,我得到的第一个错误。当我删除了参考,我得到的错误,指出我需要使用qalifyAssembly元素的app.config仅供参考GAC Oracle.DataAccess.dll。

I win! So what I did before: I get Oracle.DataAccess.dll from Oracle Client bin directory and referenced it from my project assembly. When I run NHibernate Configure() function I get first error. When I removed the reference I get error that says that I need to use qalifyAssembly element in app.config for reference GAC Oracle.DataAccess.dll.

所以我做了什么来解决这个问题: 我去了GAC和比较版本的Oracle.DataAccess的DLL有一个我以前引用。它是:版本,有人认为,最近我引用的是:10.xxx和版本的dll在GAC(actualy有数据访问的DLL数)是2.xxx这里: HTTP://tiredblogger.word$p$pss.com/2008/ .. S-库/ 我发现类似的错误我,和我说这code

So what I did to resolve it: I went to GAC and compare versions of Oracle.DataAccess dlls there with one I referenced before. It was: version of that that I recently referenced was: 10.x.x.x and version of dll in GAC (actualy there were number of DataAccess dlls) was 2.x.x.x. Here: http://tiredblogger.wordpress.com/2008/ ... s-library/ I found error similar to my, and I added this code

<runtime>
       <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
              <qualifyAssembly partialName="Oracle.DataAccess"
                     fullName="Oracle.DataAccess,
                            Version=2.111.6.20,
                            Culture=neutral,
                            PublicKeyToken=89b483f429c47342" />
       </assemblyBinding>
</runtime>

要的app.config像上面描述的和refernenced此DLL。我不知道为什么我需要做这两件事,但只有这样它的工作原理。

to app.config like described in above and refernenced this dll. I don't know why I need to do both, but only so it works.