【问题标题】:Can't connect Spring Boot and MS SQL Server 2012无法连接 Spring Boot 和 MS SQL Server 2012
【发布时间】:2021-06-22 11:09:46
【问题描述】:

我需要访问位于本地主机上的 MS SQL Server 2012。问题是,每当我尝试发送 HTTP POST 请求(调用在数据库内部写入的方法)时,都会收到以下错误:

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'admin'. ClientConnectionId:e2b2c522-55c6-406f-9762-fcd36e8472d1

有什么建议吗?

application.properties

spring.datasource.jdbcUrl=jdbc:postgresql://localhost:5432/depiva_test_localhost
spring.datasource.username=postgres
spring.datasource.password=password
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.datasource.second.jdbcUrl=jdbc:sqlserver://localhost;databaseName=BetonWinSQL;
spring.datasource.second.username=admin
spring.datasource.second.password=mypassword

【问题讨论】:

  • 您能否更新您的问题以显示您如何使用spring.datasource.second.* 属性来定义DataSource bean?

标签: sql spring spring-boot mssql-jdbc


【解决方案1】:

您正在使用 PostgreSQL 而不是 MSSQL 的设置 这是它的外观

spring.datasource.url=jdbc:sqlserver://localhost;databaseName=springbootdb
spring.datasource.username=sa
spring.datasource.password=Projects@123
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.hibernate.ddl-auto = create-drop

https://springframework.guru/configuring-spring-boot-for-microsoft-sql-server/

【讨论】:

  • 我有两个数据库连接。一个用于 PostgreSQL 服务器,另一个用于 MS SQL Server。
猜你喜欢
  • 2018-02-26
  • 1970-01-01
  • 1970-01-01
  • 2018-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-25
  • 1970-01-01
相关资源
最近更新 更多