简体   繁体   English

SQL Server的休眠身份验证错误

[英]Hibernate Authentication Error with SQL Server

I am having a difficult time trying to set a connection with hibernate to a SQL Server. 我在尝试设置与休眠到SQL Server的连接时遇到了困难。 I should create a connection to the following data source DataSource=server,port. 我应该创建到以下数据源DataSource = server,port的连接。 It seem strange that the port must be specify with a comma instead of : 必须用逗号而不是指定端口,这似乎很奇怪。

When I connect to it through Visual Studio 2012 this is how it looks: 当我通过Visual Studio 2012连接到它时,它的外观如下:

Data Source=server,17001;Initial Catalog=database;User ID=username 数据源=服务器17001;初始目录=数据库;用户ID =用户名

In order to connect it I create the following hibernate configuration file: 为了连接它,我创建了以下休眠配置文件:

<hibernate-configuration>
 <session-factory name="">
  <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
  <property name="hibernate.connection.url">jdbc:sqlserver://server.fqdn</property>
  <property name="hibernate.connection.port">port</property>
  <property name="hibernate.connection.username">username</property>
  <property name="hibernate.connection.password">password</property>
  <property name="hibernate.connection.databasename">database</property>
  <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
  <property name="hibernate.enable_lazy_load_no_trans">true</property>
  <property name="connection.pool_size">1000</property>
 </session-factory>
</hibernate-configuration>

But I get the following Exception when the connection is attempted: 但是尝试连接时出现以下异常:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'username'. 引起原因:com.microsoft.sqlserver.jdbc.SQLServerException:用户“用户名”的登录失败。 ClientConnectionId:c619c1dc-2c6c-4c6e-bc81-7d3619ee9ff1 ClientConnectionId:c619c1dc-2c6c-4c6e-bc81-7d3619ee9ff1

I know for sure that the user and password are correct as I am using them to connect to the database through Visual Studio 2012 and they works fine. 我肯定知道用户名和密码正确无误,因为我正在使用它们通过Visual Studio 2012连接到数据库,并且它们工作正常。 Any idea of how should I face it? 我应该如何面对这个想法?

I forgot to mark this as resolved. 我忘记将其标记为已解决。 The issue was that I was specifying the port as a separate property: 问题是我将端口指定为单独的属性:

<property name="hibernate.connection.port">port</property>.

When I add it to the connection string parameter 当我将其添加到连接字符串参数时

<property name="hibernate.connection.url">jdbc:sqlserver://server.fqdn:port</property>

it works 有用

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM