持久层配置期间发生异常 [英] An exception occurred during configuration of persistence layer

查看:118
本文介绍了持久层配置期间发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用ASP.NET中的MySql在Nhibernate中做一个项目.在执行代码的过程中,我遇到了类似的错误

I'm doing a project in Nhibernate with MySql in asp.net. In that while executing the code I got the error like

在配置持久层时发生了异常

An exception occurred during configuration of persistence layer

在下面的行

ISessionFactory factory = new NHibernate.Cfg.Configuration().Configure).BuildSessionFactory();

所以让我帮忙排除错误.

So let me help to trouble shoot the error.

这是我的配置文件

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <!-- an ISessionFactory instance -->
  <session-factory>
    <!-- properties -->
    <property name="connection.provider">
      NHibernate.Connection.DriverConnectionProvider
    </property>
    <property name="connection.driver_class"> 
      NHibernate.Driver.MySqlDataDriver
    </property>
    <property name="connection.connection_string">
      Server=localhost;Database=hrms;User ID=test;Password=test;
    </property>
    <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
    <property name="show_mysql">true</property>
    <!-- mapping files -->
    <mapping resource="WebApp1.Job.hbm.xml" assembly="WebApp1" />
  </session-factory>
</hibernate-configuration>

推荐答案

也许配置不完整?尝试如下进行手动配置初始化:

Incomplete configuration perhaps? Try manual configuration initialization like the following:

NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.SetProperty("dialect", "NHibernate.Dialect.MySQLDialect");
cfg.SetProperty("connection.driver_class", "NHibernate.Driver.MySqlDataDriver");
cfg.SetProperty("connection.connection_string", "Server=YourServer;Database=YourDatabase;User ID=YourId;Password=YourPass;CharSet=utf8");
cfg.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu");  
cfg.AddAssembly("Your.Assembly.Name");  
ISessionFactory sessionFactory = cfg.BuildSessionFactory();

如果一切正常,请根据需要将其移至XML.

If everything works, move it to XML if you like.

这篇关于持久层配置期间发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆