Is it possible to use (freely) nhibernate with an odbc connection?

I need to use my own odbc driver.

All I need to pass as a connection string is a DSN.

How do I do this with (smooth) nhibernate? FluentNHibernate.Cfg.Db only offers the OdbcConnectionStringBuilder class with the DSN method. How can i use this?

+4
source share
2 answers

You can create your own OdbcConfiguration class, which derives from PersistenceConfiguration .

Depending on your database, you will have to replace Dialect in the following class.

 public class OdbcConfiguration : PersistenceConfiguration<OdbcConfiguration, FluentNHibernate.Cfg.Db.OdbcConnectionStringBuilder> { protected OdbcConfiguration() { Driver<NHibernate.Driver.OdbcDriver>(); } public static OdbcConfiguration MyDialect // <-- insert any name here { get { // insert the dialect you want to use return new OdbcConfiguration().Dialect<NHibernate.Dialect.MyDialect>(); } } } 

Then in Fluent NHibernate use OdbcConfiguration :

 // replace MyDialect here, too Fluently.Configure() .Database(OdbcConfiguration.MyDialect.ConnectionString("DSN=...;UID=...;PWD=...") .Driver<NHibernate.Driver.OdbcDriver>() .Dialect<NHibernate.Dialect.MyDialect>() // <-- again, change this .etc... 
+8
source

Could not find sample code using OdbcConnectionStringBuilder after a quick search. Free NHibernate does not seem to have a corresponding “OdbcConfiguration” object for use with OdbcConnectionStringBuilder. If you are not using Fluent NHibernate to configure the database (you can still use Fluent for all object mappings), you can configure through the hibernate.cfg.xml file, see the DB2 configuration example for using the ODBC provider.

+1
source

All Articles