views:

19

answers:

1

We are using Nhibernate to connect to DB2 database. From my C# application. We are able to connect using Odbc and OleDB driver but we need to connect using IBM DB2 driver (IBM.Data.DB2.dll).

We are not able to connect using it. We are getting below error seems NHibernate is not able to create NHibernate.Driver.DB2Driver.

{"Could not create the driver from NHibernate.Driver.DB2Driver."}

This is the connection string we are using.

<property name="dialect">NHibernate.Dialect.DB2Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.DB2Driver</property>
<property name="connection.connection_string">Provider=IBMDADB2;Database=Databasename;Hostname=hostname;Protocol=TCPIP; Port=50000;Uid=username;Pwd=password;</property>
A: 

According to the source code, a HibernateException is thrown when the IBM.Data.DB2 assembly cannot be loaded. Make sure that IBM.Data.DB2 is referenced by your project. If you don't reference it in your project, the assembly will not be copied to the output directory and NHibernate will not be able to find it. (The other option would be to install it in the GAC, but I prefer a project reference so that your application is xcopy deployable.)

James Kovacs