0

I am using a domain user account to connect to SQL server database and when I try to start my server I get the exception com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user error. I am using sqljdbc4-1.0.jar drivers.

The userid I am using is a service user id (a domain user id) which is different from the userid I am logged into windows. So I cannot use IntegratedSecurity option. my connection url looks like

jdbc:sqlserver://server;authentication=SqlPassword;userName=domain\username;password=mypassword;databaseName=mydatabase;

I even tried providing the username and password separately and even that also did not work. I searched a lot but could not find any relevant help. Please help.

user2928913
  • 223
  • 1
  • 6
  • 15
  • Windows Authentication mode is what to use with the domain credentials the process runs under: `jdbc:sqlserver://server;integratedSecurity=true;databaseName=mydatabase` – Alex K. May 10 '16 at 17:06
  • @Alex, As I mentioned, I need to use the service user id, and I do not want the application to pick up my user id from the local machine, So I cannot use IntegratedSecurity. – user2928913 May 10 '16 at 17:09

1 Answers1

0

I recently had the same problem with java app(Spring Boot) connecting with a domain user and wasting a few days doing it, but I managed, here's how I did it, hope it helps:

pom.xml:

<dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
        <version>1.3.1</version>
    </dependency>

properties file:

jdbc:jtds:sqlserver://host:port;databaseName=dbname;instance=SQLDEV;domain=domainname.corp;user=userdb;password=p4ssw0rd;

example:

my file has too many options remove it if you don't use it

spring.application.name=app-name
spring.profiles.active=dev
spring.datasource.hikari.connection-test-query=SELECT 1
spring.datasource.url=jdbc:jtds:sqlserver://100.50.50.56/MinWeb;instance=SQLDEV;domain=domainname.corp;user=userdb;password=password;
spring.datasource.test-while-idle=true
spring.datasource.validation-query=SELECT 1
spring.datasource.time-between-eviction-runs-millis=60000
spring.datasource.remove-abandoned=true
spring.datasource.driver-class-name=net.sourceforge.jtds.jdbc.Driver
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLServerDialect
spring.jpa.properties.hibernate.hbm2ddl.auto=none

Here are some links that I consulted:

Connect To SQL Server With Windows Authentication From A Linux Machine Through JDBC

Configure HikariCP in Spring Boot with JTDS

Create a jTDS connection string

T+

Dharman
  • 30,962
  • 25
  • 85
  • 135
Marcos Rufino
  • 141
  • 2
  • 6