'Login failed for user' when connecting to a docker hosted SQLServer instance
See original GitHub issueDriver version or jar name
mssql-jdbc-7.0.0.jre8.jar
SQL Server version
(Using docker) Microsoft SQL Server 2017 (RTM-CU9) (KB4341265) - 14.0.3030.27 (X64) Jun 29 2018 18:02:47 Copyright © 2017 Microsoft Corporation Express Edition (64-bit) on Linux (Ubuntu 16.04.4 LTS)
Client operating system
Microsoft Windows Version 1803 (17134.112)
Java/JVM version
java version “1.8.0_181” Java™ SE Runtime Environment (build 1.8.0_181-b13) Java HotSpot™ 64-Bit Server VM (build 25.181-b13, mixed mode)
Table schema
None
Problem description
I’m using liquibase, a database change migration tool, to update my databases. I tried to execute the migrations using a mssql docker image. When trying to connect the following exception occurs:
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'. ClientConnectionId:5cbf9253-ffe6-4b3f-a9b7-fb7f2eaa04e6
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:132)
at liquibase.integration.commandline.Main.doMigration(Main.java:953)
at liquibase.integration.commandline.Main.run(Main.java:191)
at liquibase.integration.commandline.Main.main(Main.java:129)
Caused by: liquibase.exception.DatabaseException: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'. ClientConnectionId:5cbf9253-ffe6-4b3f-a9b7-fb7f2eaa04e6
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:254)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:149)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:97)
... 3 common frames omitted
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'. ClientConnectionId:5cbf9253-ffe6-4b3f-a9b7-fb7f2eaa04e6
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:254)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:258)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:104)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:4772)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3581)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:81)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3541)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7240)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2869)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2395)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2042)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1889)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1120)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:700)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:246)
... 5 common frames omitted
Logging in using Sql Server Management Studio works fine as well as creating a database in the docker container using sqlcmd.exe with the same credentials.
If I execute the same batch file against a locally installed SQL Server (2016 - I don’t have a newer version installed) it is working fine. But I can’t get it to run against the SQL Server in the docker container.
I can’t figure out what’s the problem here.
Expected behavior and actual behavior
Logging in using the same credentials as with SSMS or SQLCMD should work via jdbc.
Repro code
I created a small sample that leads to the exception here: https://github.com/papauorg/mssql-jdbc-login-sample/tree/master
1.) Start the docker container (latest mssql-image) using docker-compose up
2.) Execute the liquibase batch file (that’s using the jdbc driver) RunLiquibaseAgainstDocker.bat
Could you please have a look at this? Would be great if you could tell me if i’m doing something wrong, here?
Thanks, Philipp
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Hi @papauorg
I tested with your repro, and turns out, JDBC Driver is able to connect successfully with
0.0.0.0
as servername while ODBC driver cannot identify0.0.0.0
then. This is due to the way docker maps ports to host machines. It uses0.0.0.0
to map the port unless hostname is specified.You can make a small change in
docker-compose.yml
by specifying ports as below:Also, specify same host in
RunLiquidbaseAgainstDocker.bat
file:ServerName=127.0.0.1
so that ODBC Driver can identify it. The JDBC Driver can resolve host127.0.0.1
tolocalhost
for connecting to this server but ODBC Driver cannot do so. Explicitly specifying host IP address makes it work for both drivers.The JDBC Driver can connect to
0.0.0.0
and notlocalhost
. The ServerName you provided in Run… script was ‘localhost’ 😃