1

I am using microsoft sql server,

If i open intellij, open new database connection in database tool window =>

enter image description here

and in advanced type i add: enter image description here

The connection works. However now i want to connect to this ms sql server with spring jpa. So what i am using is:

spring.datasource.url=jdbc:jtds:sqlserver://<host>:<port>;instance=<instance>;domain=<domain>;useNTLMv2=true
spring.datasource.username=<user>
spring.datasource.password=<password>
spring.datasource.driverClassName=net.sourceforge.jtds.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.SQLServerDialect

And it just says "login for user failed"

In my pom i am using:

<!-- jpa -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <version>${spring.jpa.version}</version>
</dependency>

<dependency>
    <groupId>jtds</groupId>
    <artifactId>jtds</artifactId>
    <version>1.2</version>
</dependency>

Why does it work with database tool window, but not with jpa?

Thanks for help!

Johnyb
  • 980
  • 1
  • 12
  • 27

1 Answers1

2

Your are mixing JDBC driver connecting with sprig data JPA connection, for JPA proper connection you can change the drive class name to

spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver

Then the dialect can be

spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect

And finally add the proper url and remove JDBC driver relavent dependencies

spring.datasource.url=jdbc:sqlserver://localhost;databaseName=<dbname>

Remaining properties will be same as your, see both examples in here .

Lunatic
  • 1,519
  • 8
  • 24
  • Please see here as well .https://stackoverflow.com/a/4574118/15758781 – Lunatic Mar 03 '22 at 14:23
  • if i dont use jtds driver, it refuses connection even in intellij database tool window. I tried to use your properties, but the error remains 'login failed for user' – Johnyb Mar 03 '22 at 18:32