使用域用户标识连接到sql server - SQLServerException:用户

时间:2016-05-10 16:57:36

标签: java sql-server database-connection

我正在使用域用户帐户连接到SQL Server数据库,当我尝试启动服务器时,我收到异常com.microsoft.sqlserver.jdbc.SQLServerException:登录失败,因为用户错误。我正在使用sqljdbc4-1.0.jar驱动程序。

我使用的用户标识是服务用户标识(域用户标识),它与我登录到窗口的用户标识不同。所以我不能使用IntegratedSecurity选项。我的连接网址看起来像

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

我甚至尝试单独提供用户名和密码,甚至也没用。我搜索了很多,但找不到任何相关的帮助。请帮忙。

1 个答案:

答案 0 :(得分:0)

我最近在与域用户连接的 java 应用程序(Spring Boot)上遇到了同样的问题并浪费了几天时间,但我设法做到了,这是我的方法,希望对您有所帮助:

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>

属性文件:

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

示例:

我的文件有太多选项,如果你不使用它就删除它

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

以下是我查阅的一些链接:

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+