Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not create the driver from NHibernate.Driver.NpgsqlDriver

I've inherited a C#/NHibernate/MS SQL Server project and am new to NHibernate. One of the first tasks given to me was to migrate the database from MS SQL Server (2008 R2) to Postgresql 9.2. I'm using the Npgsql 2.0.12 (.net 2.0 version). The Mono.Security.dll and Npgsql.dll are included in my project References and they exist in my bin directory. When the code executes the following line:

SessionFactory.OpenSession();

an exception is thrown with the message

"Could not create the driver from NHibernate.Driver.NpgsqlDriver."

Searching the web, gave me a few ideas but none have worked. This code I've inherited is in production at several clients with no issues using MS SQL Server. Here is my hibernate.cfg.xml file:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property>
    <property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
    <property name="connection.connection_string">server=localhost;Port=5432;Database=vehicletracker;User Id=postgres;Password=********;</property>
  </session-factory>
</hibernate-configuration>

I did not forget to include "using Npgsql;", it is there. Any suggestions?

Regards,

B

like image 808
Woolly Avatar asked Nov 09 '12 14:11

Woolly


1 Answers

I found the answer to my own question. There were several issues specific to my work environment but ultimately the Mono.Security.dll and Npgsql.dll were not available in my final output directory. The two files were present in the bin directory of my Data Access Layer (a class library) but not in the bin directory of my Test Project that called the class library. Everything is working fine now.

like image 92
Woolly Avatar answered Sep 21 '22 22:09

Woolly