使用nhibernate出现Could not find the dialect in the configuration

初次使用nhibernate,学着去做一个更新sql2008数据库的demo,出现“Could not find the dialect in the configuration ”,以下是俺之前参照别人的例子使用的config文件

<configSections>
    <section name="hibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  </configSections>
<hibernate>
    <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
    <add key="dialect" value="NHibernate.Dialect.MsSql2008Dialect"/>
    <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
    <add key="connection.connection_string" value="Server=localhost;initial catalog=parkTest;Integrated Security=SSPI"/>
 </hibernate>

人家说的就是能通过,俺的就是出现上面错误,很无语~于是继续google,终于找到了答案

<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.MsSql2008Dialect
      </property>
      <property name="connection.driver_class">
        NHibernate.Driver.SqlClientDriver
      </property>
      <property name="connection.connection_string">
        data source=.\SQLEXPRESS; User ID=sa;Password=huitian;initial catalog=parkTest;Integrated Security=SSPI
      </property>
    </session-factory>
  </hibernate-configuration>

配置文件改成上面那样后,数据库终于可以添加信息。对于上面文件中的connection.connection_string还要稍微说明一下,如果其中的data source使用Server=;会出现“在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接) ”的错误。详细说明可参考http://www.cnblogs.com/xpxu/archive/2010/01/29/1659476.html

  之后有时间会继续将自己遇到的情况mark上来~

原文地址:https://www.cnblogs.com/alirong/p/2501594.html