Issue with using ODP with NHibernate

冷暖自知 提交于 2019-12-13 07:25:29

问题


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'

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

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

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


回答1:


I get it working!!!

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.

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>

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.



来源:https://stackoverflow.com/questions/3084396/issue-with-using-odp-with-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!