无法从NHibernate.Driver.SQLServerDriver创建驱动程序

问题描述

我对hibernate.cfg.xml使用以下代码

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MssqlAzure2008Dialect</property>
    <property name="connection.driver_class">NHibernate.Driver.sqlServerDriver</property>
    <property name="connection.connection_string">Server=tcp:usedctp000dbs01.database.windows.net,1433;Initial Catalog=usedctp000db01;Persist Security Info=False;User ID={user};Password={password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication="Active Directory Password";</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

当我运行BuildSessionFactory时,出现以下异常

NHibernate.HibernateException:'无法从以下位置创建驱动程序 NHibernate.Driver.sqlServerDriver。'

我发现了类似的问题,但与MysqL有关,解决方案是添加MysqL.Data.dll,您知道是否应该为Azure sql Server上传类似的文件吗?我可以在哪里找到它?我尝试添加sqlsrv32.dll,但出现以下错误

enter image description here

解决方法

已安装System.Data.SqlClient enter image description here

它也没有出现在参考管理器Add Referenceenter image description here

要解决这个问题,我必须在包中找到de dll的路径

enter image description here enter image description here

,然后通过“参考管理” Add Reference浏览文件将其添加。但是会显示一个新错误

TypeLoadException:无法加载类型 NHibernate.Driver.SQLServerDriver。可能的原因:没有程序集名称 指定。

我们只需解决此问题,即可从配置中删除以下行

NHibernate.Driver.SQLServerDriver

似乎不是必需的,当您指定方言时会自动检测到