views:

180

answers:

1

Hi I want assign connection string for NHibernate using following code and getting exception (bold).

log4net.Config.DOMConfigurator.Configure();
Configuration config = new Configuration();
IDictionary props = new Hashtable();

props["hibernate.connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
props["hibernate.dialect"] = "NHibernate.Dialect.MsSql2000Dialect";
props["hibernate.connection.driver_class"] = "NHibernate.Driver.SqlClientDriver";
props["hibernate.connection.connection_string"] = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Sample;Data Source=HYDHTC92318D\SQLEXPRESS";
props["hibernate.connection.current_session_context_class"] = "web";
props["hibernate.connection.show_sql"] = "true";

props["hibernate.connection.proxyfactoryfactory.factory_class"] = "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";

foreach (DictionaryEntry de in props)
{
  config.SetProperty(de.Key.ToString(), de.Value.ToString());
}

config.AddAssembly("nhibernator");
factory = config.BuildSessionFactory();
session = factory.OpenSession();

The ProxyFactoryFactory was not configured. Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers. Example: NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu Example: NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle

Please let me know the solution. Regards JCReddy

A: 

See here for a solution:

http://stackoverflow.com/questions/1984976/how-to-load-application-settings-to-nhibernate-cfg-configuration-object/

I haven't tested this, but you may want to try changing:

props["hibernate.connection.proxyfactoryfactory.factory_class"] =
  "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";

to:

props["proxyfactory.factory_class"] =
  "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle";

The proxyfactory isn't part of the connection.

Michael Maddox
Hi Michael I used code mentioned in the above link, and is working, thanks a lot.
jcreddy