尝试从Windows机器上运行的Java应用程序通过Windows身份验证连接到MS SQL服务器。
连接字符串:

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

得到连接错误:

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:?]


如何理解此错误以及如何解决?

UPD

如果我按以下方式删除authenticationScheme=JavaKerberos

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


我有错误:

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

离开authenticationScheme=JavaKerberos并删除integratedSecurity=true如下:

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


给出错误:

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]

最佳答案

该应用程序运行在Linux计算机上,该计算机是否已加入Windows域?

如果没有,那么您可能需要使用SQL身份验证:

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


否则,可以尝试不指定authenticationScheme=JavaKerberos和默认端口的情况:

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

10-08 19:56