我的 Hibernate 配置与 SQL Server 数据库的连接遇到了一个小问题, 所以我的应用程序结构只是为了简单测试,这里是架构:在此处输入图像描述 所以这是 我的 hibernate.xml.cfg :
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration>
<session-factory xmlns="urn:nhibernate-configuration-2.2">
<property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.url">jdbc:jtds:sqlserver://OUSSEMA;DatabaseName=DB_GestionCompte</property>
<property name="connection.username">sa</property>
<property name="connection.password">123</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
a
我在启动项目时收到此错误:
System.TypeInitializationException: 'The type initializer for 'HibernateUtil' threw an exception.'
HibernateConfigException: An exception occurred parsing configuration :The 'name' attribute is invalid - The value 'connection.url' is invalid according to its datatype 'Union' - The value 'connection.url' is not valid according to any of the memberTypes of the union.
在 DataService.cs 的这一行中:ISessionFactoryfactory = HibernateUtil.GetSessionFactory();
我尝试了不同的休眠配置方法,但没有一个方法仍然出现相同的错误,同时我确信 sql 身份验证有效且电线正确
查看文档,您的配置似乎使用了无法识别的属性名称。
例如,
connection.url
,应该是connection.connection_string
。我在文档中看不到 connection.username
或 connection.password
的等效项。这些通常包含在连接字符串中。