Spring Boot - Connect to a SQL Server Database using Windows Authentication

Viewed 1982

I'm writing a Spring Boot application to connect to a SQL Server database and extract some data into a .csv file.

The DBA has created a db user and gave read access to the specific tables my app needs. And that db user is mapped to a LDAP Service User Account. Now I'm trying to access that DB using the Service Account. I'm using IntelliJIdea to create this app. When I try to run the application it gets my login Windows User to connect to the database rather than the Service Account.

How/Where can I give the Service Account Username and Password to connect to the database avoiding my login user to be used for Authentication?

My Development Env,

  • Windows 7

  • Java 8

  • IntelliJIdea Ultimate 2019.3

  • DBeaver Universal DB Client 7.0.4

Steps I followed,

1) Downloaded mssql-jdbc-8.2.2

2) Added auth dll and jar in the Java/JDK/bin

3) Added auth dll in windows/system32

4) in the application.properties file

spring:
 datasourse:
  url: jdbc:sqlserver://<host-name>:<port-number>;databaseName=<db-name>;integrationSecurity=true;

NOTE: I can successfully connect to the db using the service account when I ran the DBeaver DB Client by "Shift + right click" and selected "Run as different user" and put service account details.

1 Answers

I recommend to keep opened a cmd.exe (Windows Command Line) started with "Run as different user" and with that service account then you can test your application within this window.

Related