我刚接触到nhibernate,正试图使用它连接到DB2。经过反复的试验和错误的研究,以及更多的试验和错误的研究,我终于找到了一个我找不到答案的错误。
错误消息显示:“用户必须提供ADO.NET连接-nhibernate没有创建它。”
这个错误不是很有帮助。这是否意味着我需要1)在配置文件中放置连接字符串,或者2)是否需要将连接传递到工厂?如果1为真,这是强制性的吗?如果是这样,那么为什么我们能够将连接对象传递到会话中,这正是我想要做的?
如果2)为真,如何将连接对象传入工厂?
提前谢谢。下面是我的代码片段,可能会有所帮助:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.DB2400Dialect</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
</session-factory>
</hibernate-configuration>
</configuration>
try
{
Configuration cfg = new Configuration();
cfg.AddInputStream(NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize(persistentClass));
SessionFactory = cfg.Configure().BuildSessionFactory(); //HERE I GET THE EXCEPTION
}
catch (Exception ex)
{
throw new Exception("NHibernate initialization failed", ex);
}