6

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

Woolly
  • 151
  • 1
  • 4

2 Answers2

9

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.

Woolly
  • 151
  • 1
  • 4
1

If you're using NuGet for the nhibernate libraries try uninstalling the packages and reinstall them. I'm sure there is a more efficient way someone knows of to fix this kind of issue but for me it solved this exact issue.

Tom D.
  • 21
  • 2
  • Hi Tom, thanks for taking the time to assist. I'm not using NuGet since my IDE is Visual Studio 2008. I did delete and replace my nHibernate and Npgsql dll's but still no luck. Again, using MS SQL Server works fine but attempting a connection with Npgsql throws an exception. – Woolly Nov 12 '12 at 20:16