Custom Connection Provider with NHibernate 2.0 (Beta 2)

Sunday, 29 June 2008 10:34 by PhilJapikse
I don't like having connection strings in config files, especially smart client config files. However, there are times when it is a necessity. So, the other "deal breaker" for me with NHibernate was to determine if I could create a custom connection provider that would allow me to have an encrypted connection string in the configuration, handle the decryption, then pass the appropriate information to NHibernate core.

Turns out this is a very simple endeavor. Create a class that derives from DriverConnectionProvider, and override one method from the base:

protected override string GetNamedConnectionString(System.Collections.Generic.IDictionary settings)
{
//do work to return an unencrypted connection string
}

Simple as that!

Happy Coding!
Tags:   , , ,
Categories:   NHibernate
Actions:   E-mail | Permalink | Comments (3) | Comment RSSRSS comment feed

Comments

March 30. 2010 04:39

Andoni

To make that work you need to change connection.provider property in config file. Isn´t it?

I did so:

<property name="connection.provider">BPTDAL.DriverConnectionProviderBPT</property>

But still have this error:

"Could not instantiate connection provider: BPTDAL.DriverConnectionProviderBPT"

What else is missing. Do I need to tell him the assembly name? How?

Thanks in advance,
Andoni Ripoll

Andoni

March 30. 2010 04:50

Andoni

And then answer is, write this:

<property name="connection.provider">BPTDAL.DriverConnectionProviderBPT, BPTDAL</property>
      
Greetings,
Andoni Ripoll

Andoni

March 30. 2010 04:56

PhilJapikse

That is correct. Guess it would have helped to put that in the post Smile.  Good catch!

PhilJapikse

Add comment




  Country flag

biuquote
Loading