简体   繁体   English

无法实例化连接提供程序:NHibernate.Driver.MySqlDataDriver

[英]Could not instantiate connection provider: NHibernate.Driver.MySqlDataDriver

I'm making a simple web project using NHibernate and i'm stuck at this error whenever i try to build the sessionfactory. 我正在使用NHibernate制作一个简单的Web项目,每当我尝试建立sessionfactory时,我都会遇到这个错误。

The line that causes the exception is this 导致异常的行是这个

ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();

People with similar problem seems to solve them by referencing Mysql.data.dll which i've already done, and checked that the dll is in my bin folder. 有类似问题的人似乎可以通过引用我已经完成的Mysql.data.dll来解决它们,并检查dll是否在我的bin文件夹中。

i suspect the fault lies in my hibernate.cfg.xml which looks like this 我怀疑故障出在我的hibernate.cfg.xml中,它看起来像这样

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
<property name="connection.provider">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
<property name="connection.connection_string">connectionstring</property>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<mapping assembly="Mcgvd" />
</session-factory>
</hibernate-configuration>

the tutorial i followed to make this project was using a helperclass to create the sessionfactory looking like this 我遵循的使这个项目的教程是使用一个helperclass来创建sessionfactory,如下所示

public sealed class NHibernateHelper
{
    private const string CurrentSessionKey = "nhibernate.current_session";
    private static readonly ISessionFactory sessionFactory;

    static NHibernateHelper()
    {
        sessionFactory = new Configuration().Configure().BuildSessionFactory();
    }

    public static ISession GetCurrentSession()
    {
        HttpContext context = HttpContext.Current;
        ISession currentSession = context.Items[CurrentSessionKey] as ISession;

        if (currentSession == null)
        {
            currentSession = sessionFactory.OpenSession();
            context.Items[CurrentSessionKey] = currentSession;
        }

        return currentSession;
    }

    public static void CloseSession()
    {
        HttpContext context = HttpContext.Current;
        ISession currentSession = context.Items[CurrentSessionKey] as ISession;

        if (currentSession == null)
        {
            // No current session
            return;
        }

        currentSession.Close();
        context.Items.Remove(CurrentSessionKey);
    }

    public static void CloseSessionFactory()
    {
        if (sessionFactory != null)
        {
            sessionFactory.Close();
        }
    }
}

hibernate.cfg.xml and hibernate.hbm.xml are both located at the root of my project. hibernate.cfg.xml和hibernate.hbm.xml都位于我项目的根目录。

What am I doing wrong here ? 我在这里做错了什么?

Your configuration is wrong. 您的配置错误。

<property name="connection.provider">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>

You've specified a driver for the connection provider, and a SQL Server CE driver when you're apparently using MySQL. 您已经为连接提供程序指定了一个驱动程序,并在显然使用MySQL的同时指定了SQL Server CE驱动程序。 Try: 尝试:

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>

besides the fault Jamie found i had to change the connection.provider property where i for some reason had put mysqldatadriver. 除了故障,杰米发现我还不得不更改connection.provider属性,由于某种原因我把mysqldatadriver放在那里。

this is the working configuration i ended up with. 这是我最终得到的工作配置。

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">connectionstring</property>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<mapping assembly="Mcgvd" />
</session-factory>
</hibernate-configuration>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HibernateException:无法从NHibernate.Driver.MySqlDataDriver创建驱动程序 - HibernateException: Could not create the driver from NHibernate.Driver.MySqlDataDriver Fluent-nhibernate 与 .net 核心 NHibernate.Driver.MySqlDataDriver - Fluent-nhibernate with .net core NHibernate.Driver.MySqlDataDriver 流利的NHibernate MappingException:无法实例化ID生成器 - Fluent NHibernate MappingException : could not instantiate id generator 无法从 NHibernate.Driver.SQLite20Driver 创建驱动程序 - Could not create the driver from NHibernate.Driver.SQLite20Driver 无法从 NHibernate.Driver.SQLServerDriver 创建驱动程序 - Could not create the driver from NHibernate.Driver.SQLServerDriver 无法从 NHibernate.Driver.OracleDataClientDriver 创建驱动程序 - Could not create the driver from NHibernate.Driver.OracleDataClientDriver NHibernate 上升 NHibernate.HibernateException : 找不到命名连接 - NHibernate rises NHibernate.HibernateException : Could not find named connection {“无法从NHibernate.Driver.DB2Driver创建驱动程序。”}我正在使用C#.net - {“Could not create the driver from NHibernate.Driver.DB2Driver.”} I am using C#.net 无法编译映射文档,无法实例化方言 class Nhibernate.Dialect.MsSql2008Dialect - Could not compile the mapping document, Could not instantiate dialect class Nhibernate.Dialect.MsSql2008Dialect Windows Server x64中与NHibernate的Oracle驱动程序连接 - Oracle Driver Connection with NHibernate in Windows Server x64
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM