How do I setup NHibernate with Visual Studio and Firebird?

三世轮回 提交于 2019-12-04 20:10:48

ok thanks everyone, I've got it sorted now. It seems I needed to call cfg.Configure() to process hibernate.cfg.xml ... once I did this there were a few other errors but they were all quite logical to fix up with error messages that made good sense.

Here's the initialization code that worked.

public Form1()
{
    cfg = new Configuration();
    cfg.Configure();

    factory = cfg.BuildSessionFactory();
    session = factory.OpenSession();
    transaction = session.BeginTransaction();

    InitializeComponent();
}

If you're using NHibernate 2.0, but following instructions referring to 1.2, the configuration xml has changed and this will be causing your issue.

Try (in app.config, omit the configSections for a standalone file):

  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="dialect">NHibernate.Dialect.FirebirdDialect</property>
      <property name="connection.driver_class">NHibernate.Driver.FirebirdClientDriver</property>
      <property name="connection.connection_string">User=sysdba;Password=masterkey;Database=C:\X\Test\Timer\Timer.FDB;Dialect=3;ServerType=1;</property>
    </session-factory>
  </hibernate-configuration>

cfg.Configure();

really helped...Thanks a lot. Earlier i was using

cfg.AddAssembly(Assembly.GetCallingAssembly());

without success

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!