我正在使用NHibernate製作一個簡單的Web項目,每當我嘗試構建sessionfactory時,我都會陷入此錯誤。無法實例化連接提供程序:NHibernate.Driver.MySqlDataDriver
導致異常的行是這樣的
ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
人有類似的問題似乎被引用Mysql.data.dll,我已經完成了解決這些問題,並檢查該DLL是在我的倉夾。
我懷疑故障出在我的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>
教程我也跟着做這個項目是使用助手類來創建的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和hibernate.hbm.xml都位於我的項目的根目錄。
我在這裏做錯了什麼?
啊,我會嘗試,當我回家。我以爲自己落在了許多複製/粘貼的坑中,但無法弄清楚在哪裏。 – KristianMedK