简体   繁体   中英

Windows Authentication problem while connecting to MSSQL server from JDBC

Trying to connect to MS SQL server via Windows Authentification from Java application that runs on Linux machine. Connection string:

jdbc:sqlserver://192.168.1.50\\SQLEXPRESS:1433;DatabaseName=MyData;integratedSecurity=true;authenticationScheme=JavaKerberos

Got connection error:

com.microsoft.sqlserver.jdbc.SQLServerException: Integrated authentication failed. ClientConnectionId:42aee675-fd0d-489e-af73-574ae5c304fa
       at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2670) ~[mssql-jdbc-6.4.0.jre8.jar:?]
       at com.microsoft.sqlserver.jdbc.KerbAuthentication.intAuthInit(KerbAuthentication.java:131) ~[mssql-jdbc-6.4.0.jre8.jar:?]
       at com.microsoft.sqlserver.jdbc.KerbAuthentication.GenerateClientContext(KerbAuthentication.java:399) ~[mssql-jdbc-6.4.0.jre8.jar:?]
       at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:4306) ~[mssql-jdbc-6.4.0.jre8.jar:?]
       at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3409) ~[mssql-jdbc-6.4.0.jre8.jar:?]
       at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:85) ~[mssql-jdbc-6.4.0.jre8.jar:?]
       at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3373) ~[mssql-jdbc-6.4.0.jre8.jar:?]
       at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7344) ~[mssql-jdbc-6.4.0.jre8.jar:?]
       at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2713) ~[mssql-jdbc-6.4.0.jre8.jar:?]
       at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2261) ~[mssql-jdbc-6.4.0.jre8.jar:?]
       at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1921) ~[mssql-jdbc-6.4.0.jre8.jar:?]
       at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1762) ~[mssql-jdbc-6.4.0.jre8.jar:?]
       at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1077) ~[mssql-jdbc-6.4.0.jre8.jar:?]

How to understand this error and how to fix it?

UPD

If I remove authenticationScheme=JavaKerberos as following:

jdbc:sqlserver://192.168.1.50\SQLEXPRESS:1433;DatabaseName=MyData;integratedSecurity=true;

I have error:

java.sql.SQLException: No suitable driver found for
       at java.sql.DriverManager.getConnection(DriverManager.java:689) ~[?:1.8.0_171]
       at java.sql.DriverManager.getConnection(DriverManager.java:247) ~[?:1.8.0_171]

UPD 2

Leaving authenticationScheme=JavaKerberos and removing integratedSecurity=true as following:

jdbc:sqlserver://192.168.1.50\SQLEXPRESS:1433;DatabaseName=MyData;authenticationScheme=JavaKerberos

gives error:

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'myuser'. ClientConnectionId:42aee675-fd0d-489e-af73-574ae5c304fa
        at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:259) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:256) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:108) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:4548) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3409) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:85) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3373) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7344) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2713) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2261) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1921) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1762) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1077) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:623) ~[mssql-jdbc-6.4.0.jre8.jar:?]
        at java.sql.DriverManager.getConnection(DriverManager.java:664) ~[?:1.8.0_171]
        at java.sql.DriverManager.getConnection(DriverManager.java:247) ~[?:1.8.0_171]

The app run on Linux machine, is that computer joined to a windows domain?

If not, then you may need to use a SQL authentication:

jdbc:sqlserver://192.168.1.50\SQLEXPRESS;user=MyUserName;password=*****;

Otherwise, this one to try without authenticationScheme=JavaKerberos and default port specified:

jdbc:sqlserver://192.168.1.50\SQLEXPRESS;DatabaseName=MyData;integratedSecurity=true;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM