views:

294

answers:

2

Ok So I have an AS400/iSeries running v5r4. I have an application that was using classic NHibernate to connect and do some basic crud. Now I have pulled that app (which sat for 2 years) off the shelf of TFS and onto a new PC and cannot seem to get it running.

Here is my Hibernate Config:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.provider">
        NHibernate.Connection.DriverConnectionProvider
      </property>
      <property name="dialect">
        NHibernate.Dialect.DB2400Dialect
      </property>
      <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
      <property name="connection.connection_string">
        DataSource=207.206.106.19;
        Database=AS400;
        userID=XXXXXX;
        Password=XXXXXXX;
        LibraryList=FMSFILTST,BEFFILT,HRDBFT,HRCSTFT,J20##X2DEV,GLCUSTDEV,OSL@@F3DEV;
        Naming=System;
        Initial Catalog=*SYSBAS;
      </property>
      <property name="use_outer_join">true</property>
      <property name="query.substitutions">
        true 1, false 0, yes 'Y', no 'N'
      </property>
      <property name="show_sql">false</property>
      <mapping assembly="BusinessLogic" />
    </session-factory>
  </hibernate-configuration>

I have all the proper DLL's included (NHibernate, castle, iesi, antlr3 , log4 etc). Also have this line in my web.config

<runtime>
    <assemblyBinding>
      <qualifyAssembly partialName="IBM.Data.DB2.iSeries" fullName="IBM.Data.DB2.iSeries,Version=10.0.0.0,PublicKeyToken=9CDB2EBFB1F93A26,Culture=neutral"/>
    </assemblyBinding>
  </runtime>

Yet I am still getting the following error as soon as I call

NHibernate.Cfg.Configuration().Configure().BuildSessionFactory().OpenSession();

The error is as follows

Unable to cast object of type 'IBM.Data.DB2.iSeries.iDB2Connection' to type 'System.Data.Common.DbCommand'

I am dying to get some help with this. Any assistance is appreciated. Thanks!

A: 

try to add

<property name="connection.driver_class">
NHibernate.Driver.DB2400Driver
</property>
kk
+1  A: 

I had this issue when using V5r4 of the iSeries system access. The IBM.Data.DB2.iSeries.dll is compiled against .NET 1.0/1 before v6r1. Because of this it is unable to cast the IDB2Connection to IDbConnection. If you use reflector and look into the IBM dll, look under references and then look at System.Data version. Then look at the version of System.Data you are referencing in your project, I am guessing you are on 2.0.5**. If you upgrade to v6r1 or higher you should be able to cast.

Edit: Wanted to give Steve Bohlen credit for leading me down the path to discover this.

Ryan H
Sorry for the late response on this. I think this is the answer. We have had nothing but problems with V5r4 and upgrading to 6r1, while in the cards, wont happen for a long time. Our iSeries powers our entire company with a 7 terbyte database and thousands of rpg objects on it so its not an upgrade they are taking lightly. Thanks for the response on this.
chrisjlong
No worries, glad I could help. It's amazing how little information there is on this topic.
Ryan H
do you think if i just get the v6r1 version of the drivers i will be able to hit my v5r4 box with it? or is that under the hood somewhere that i cant get to it? (i.e. the drivers decide what version to use)
chrisjlong
Actually, I must not have had my coffee yesterday when I replied. Yes, I simply upgraded the dll in the project and was able to hit the box which is on V5r3 here I believe. So I don't think you would need to upgrade the version the servers sit on, just the reference you are using for access.
Ryan H
Struggling to find a link to the latest drivers. Any chance of getting one more bone?
chrisjlong