Mssql-docker: why i cant login with sa

Created on 23 Mar 2017  Â·  15Comments  Â·  Source: microsoft/mssql-docker

i use mssql-server-linux in my Mac docker.there are some steps in my installing.
1.i run those in terminal,and sqlserver is working;
sudo docker pull microsoft/mssql-server-linux
docker create -v /var/opt/mssql --name mssql microsoft/mssql-server-linux /bin/true
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=zhaobo134SA@' -p 1433:1433 --volumes-from mssql microsoft/mssql-server-linux
2.i use sql-cli (get from npm as offical document said),then runing mssql -s localhost -u sa -p zhaobo134SA@.but it shows Login failed for user 'sa'. Reason: An error occurred while evaluating the password. [CLIENT: 172.17.0.1] in logs.
i doubt that is my password wrong? i remember the default password of sa is 'root' or '1234',but didn't work.
In china ,i don't found any useful solution. so,could you tell me what is going on?

Most helpful comment

@rauljosepalma - One possibility... Since you are mounting to a host volume at docker run time, _if_ your master DB file is located in the host file and it has a different SA login password in it from a previous run, the SA_PASSWORD you pass in at docker run will be ignored and SQL Server will use the SA login password from the first run in which the master DB was created. If you don't need the database files, please stop the container, delete the files on the host, and run the container again with the new password you want.

All 15 comments

The error message you are getting 'An error occurred while evaluating the password' happens when the login is disabled and the password is wrong per multiple blog posts on the web such as this one:
http://sqlblog.com/blogs/aaron_bertrand/archive/2011/01/14/sql-server-v-next-denali-additional-states-for-error-18456.aspx

However, I think this may also be happening because you have an '@' in your password and in particular at the end of the password.

See this article:
https://msdn.microsoft.com/en-us/library/ms161962.aspx

Microsoft SQL Server passwords can contain up to 128 characters, including letters, symbols, and digits. Because logins, user names, roles, and passwords are frequently used in Transact-SQL statements, certain symbols must be enclosed by double quotation marks (") or square brackets ([ ]). Use these delimiters in Transact-SQL statements when the SQL Server login, user, role, or password has the following characteristics:
Contains or starts with a space character.
Starts with the $ or @ character.
If used in an OLE DB or ODBC connection string, a login or password must not contain the following characters: [] {}() , ; ? * ! @. These characters are used to either initialize a connection or separate connection values.

I recommend trying to create a new container and use a new password, preferably one that doesn't use $, @ or .

@twright-msft thx very much.i will try agian.

Same problem here, running on ubuntu 16.04. Using different passwords doesn't work either.

Are you getting the exact same error message? There are quite a few variations on this particular error message.

I had this error after rebuilding the image from scratch with a new password but absentmindedly forgetting to clear out the mounted data. :(

Yeah, good point. The pw will be encrypted and stored in the master DB so if you remount a new container to an existing master DB file and use a different pw then it wont work.

These are my commands:

sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=h8t7-X9IAO' -p 1433:1433 -v /var/opt/mssql:/var/opt/mssql -d microsoft/mssql-server-linux

sudo docker exec -it <container-id> /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P h8t7-X9IAO

The errorlog show:

2017-04-19 07:25:42.69 Logon       Error: 18456, Severity: 14, State: 8.
2017-04-19 07:25:42.69 Logon       Login failed for user 'sa'. Reason: Password did not match that for the login provided. [CLIENT: 172.17.0.2]

@rauljosepalma - One possibility... Since you are mounting to a host volume at docker run time, _if_ your master DB file is located in the host file and it has a different SA login password in it from a previous run, the SA_PASSWORD you pass in at docker run will be ignored and SQL Server will use the SA login password from the first run in which the master DB was created. If you don't need the database files, please stop the container, delete the files on the host, and run the container again with the new password you want.

Problem solved, thank you @twright-msft

OK, great. Glad we got that sorted out! I'm going to close out this issue.

The solution provided was not an option for me as I needed the database files. Unfortunately I did not have my original sa password used when mounting volume. The way I was able to find my old sa password was using docker history --no-trunc microsoft/mssql-server-linux and scrolling up hoping to find the last docker run command that had the SA_PASSWORD set.

Save your original sa password somewhere safe! Change it for safety, but save it. Suppose that's the jist.

Thanks for the helping @twright-msft! I solved the problem, but this does not make sense for me :(

Why not block the password with special characters in creation?

@fernandoguedes - Docker run is a non-interactive command so we can't do any validation at the time you run the command. All we can do is try to use the password you pass in via the SA_PASSWORD env var. If you provide a bad one the container will immediately stop and there will be an error message in the log.

@twright-msft pls help me with this issue..i checked all your suggestions but didn't able to solve.

This is from docker logs:
2019-04-04 13:50:02.67 spid51 Using 'dbghelp.dll' version '4.0.5'
2019-04-04 13:53:44.64 Logon Error: 18456, Severity: 14, State: 7.
2019-04-04 13:53:44.64 Logon Login failed for user 'SA'. Reason: An error occurred while evaluating the password. [CLIENT: 172.17.0.2]

this is the syntax i used to create a docker image :
docker run -e 'ACCEPT_EULA=Y' -e ‘SA_PASSWORD=1Secure*Password1’ -e ’MSSQL_PID=Developer’ -p 1401:1433 --name sqlserver -d microsoft/mssql-server-linux:2017-latest

image

I experienced the same problem when I was trying to install MSSql server on a docker container with Linux for the first time. Taken from Install SQL Server on a MAC I tried to establish a connection from Azure Data Studio but I saw Login failed for user 'sa'. The second time I've tried to login first from sql-cli.
Using mssql -u sa -p myPassw0rd I've managed to successfully log in. Then I've tried Azure Data Studio and I've managed to establish a connection as well. I'll be happy if someone explains this behavior as it seems interesting to me.
Thanks,
Stanimir

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ducatel picture Ducatel  Â·  4Comments

mateodelnorte picture mateodelnorte  Â·  6Comments

LWDArjan picture LWDArjan  Â·  3Comments

andyjansson picture andyjansson  Â·  3Comments

Myrmex picture Myrmex  Â·  3Comments